我在这里是新的在stackoverflow和新的asp.net我想问如何显示消息框在mvc asp.net。这是我的代码,但会返回NullReferenceException。感谢您的help.`如何在MVC ASP.NET中显示消息框而不返回查看()
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult myfunction(MyViewModels myModel)
{
System.Web.UI.ScriptManager script_manager = new System.Web.UI.ScriptManager();
if (ModelState.IsValid) {
createRequest(myModel);
script_manager.Page.ClientScript.RegisterStartupScript(this.GetType(), "showMyMessage", "ShowMessage('Requested Successfully.');", true);
return RedirectToAction("GeneratePDF", "Forms", myModel);
}
else
{
script_manager.Page.ClientScript.RegisterStartupScript(this.GetType(), "showMyMessage", "ShowMessage('Requested failed.');", true);
return RedirectToAction("Index");
}
}`
'的RegisterStartupScript()'是Web表单代码,而不是MVC。使用javascript。 –
请参阅[我可以从MVC控制器返回JavaScript通过Ajax请求查看](http://stackoverflow.com/questions/19541336/can-i-return-javascript-from-mvc-controller-to-view-via- ajax-request)返回JavaScript ... – Rainmaker
你应该通过AJAX请求返回错误信息为'JavaScriptResult','alert'方法在JS客户端显示消息框。 –