MVC3 ValidationSummary控件 [英] MVC3 ValidationSummary Control
本文介绍了MVC3 ValidationSummary控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创造MVC验证摘要,但我没有得到如何建立验证摘要。我已经通过验证摘要控件创建在 asp.net 验证摘要。
I am trying to create validation summary in MVC but I am not getting how to create validation summary. I have created Validation summary in asp.net by using Validation summary control.
我要显示在符号列表错误总结。那么,怎样才能在我的 MVC3 创建它?什么是更好的方式来创建它?是否有任何例子或演示?
I want to display error summary in Bullet list. So, how can I create it in MVC3? What is a better way to create it? Is there any example or demo?
我想在视图的顶部显示是这样的。
I want to display like this at the top of View.
请更正以下错误
- 所需的名字
- 姓氏要求
- First Name required
- Last Name required
推荐答案
使用
@Html.ValidationSummary() in .cshtml page.
和检查的ModelState在控制器这样
and Check ModelState in Controller like this
if (ModelState.IsValid)
{
var result = Model.Save();
if (result)
{
//ViewData["MessageFromServer"] = "<p>Saved Successfully<p>";
return RedirectToAction("Index");
}
else
{
ViewData["MessageFromServer"] = "Error while saving";
}
}
return View("Create", Model);
您将看到错误页面。
这篇关于MVC3 ValidationSummary控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文