当我执行方法时,它会返回一条错误消息,我想在引导模式中显示谁。所以我在ViewBag中放了这样的消息:
[HttpPost]
public ActionResult EnviarIncrementos(CapturaViewModel model)
{
var res = service.GetService(fechaMovimiento);
ViewBag.Message = res.Error;
return RedirectToAction("Index");
}
因此,当页面重定向到索引时,我想获取ViewBag并将其显示到模式中,如下所示:
<div class="modal" id="myModal" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static" style="overflow: hidden">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Agregar nuevo archivo</h4>
</div>
<div class="modal-body col-md-12" id="modal-body">
<div class="row">
<div class="col-md-12">
Resultados
<br />
<div class="" style="height: 150px; overflow: auto; margin-bottom:10px;">
<pre id="resultado">@ViewBag.Message</pre>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<button type="reset" id="limpiar" class="btn btn-default">Limpiar</button>
</div>
<div class="col-md-6 text-right">
<button type="button" class="btn btn-default" data-dismiss="modal" onClick="window.location.reload();">Salir</button>
</div>
</div>
</div>
</div>
</div>
</div>
JS公司:
<script>
$(document).ready(function () {
if('@ViewBag.Message' != "") {
$("#myModal").modal();
}
});
</script>
但modal没有出现,消息也不存在。我做错了什么?
注意:当chrome debug JS中的页面加载更改为:
$(document).ready(function () {
if('' != "") {
$("#myModal").modal();
}
});
所以
@ViewBag
未收到。为什么会发生这种情况?