MVC:当ModelState在Controller中有效时,显示一个弹出窗口



在ASP.NET MVC项目中,如果控制器中的ModelState.IsValid为true,我想通知用户他们的项目编号,如果用户单击";好的";或者关闭弹出窗口。我尝试使用System.Windows.Forms.MessageBox来执行此操作,但当应用程序在服务器中时,弹出窗口将不会显示。

这是我在控制器中的部分代码

// POST: CylinderReport/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(ProjectCylinderReport pctForm, string yearList, string searchRptNoString, string searchPCNString, string distList)
{
if (ModelState.IsValid)
{
// report number auto-increment
int maxReportNum = CylinderReportControllerHelper.GetMaxRptNo(db, ldapUtility);
int newReportNum = 1;
if (maxReportNum > 1)
{
newReportNum = maxReportNum + 1;
};
//var confirm = System.Windows.Forms.MessageBox.Show(("Your Report Number is " + newReportNum), "Confirm", System.Windows.Forms.MessageBoxButtons.OK);
//if (confirm == System.Windows.Forms.DialogResult.OK)
return RedirectToAction("Index", new { yearList, searchRptNoString, searchPCNString, distList });
}
....
}

控制

//var confirm = System.Windows.Forms.MessageBox.Show(("Your Report Number is " + 
newReportNum), "Confirm", System.Windows.Forms.MessageBoxButtons.OK);
//if (confirm == System.Windows.Forms.DialogResult.OK)
// Add TempData
TempData["MsgAlert"] = "Your Report Number is " + newReportNum"";

return RedirectToAction("Index", new { yearList, searchRptNoString, 
searchPCNString, distList });

查看Html添加模式

<div class="modal fade text-left" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel110" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header bg-success white">
<img src="~/Content/WebSiteIMG/bell.gif" style="width:30px" />
<h5 class="modal-title" id="myModalLabel110">&nbsp;&nbsp; Message &nbsp;&nbsp;</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body text-center">
<br />
<h5> @TempData["MsgAlert"]</h5>
<br />
</div>
</div>
</div>
</div>

Java

@if (TempData["MsgAlert"] != null)
{
<script>
$('#myModal1').modal('show');
$('#myModal1').on('shown.bs.modal', function () {
var $me = $(this);
$me.delay(3000).hide(0, function () {
$me.modal('hide');
});
});
</script>
}

最新更新