不显示MVC4验证错误信息 [英] Validation error message not displaying MVC4
本文介绍了不显示MVC4验证错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用MVC4。
验证失败,但都没有得到验证显示错误消息。
Validation is failing but validation error messages are not getting displayed.
这是我的模型。
public class Configuration
{
public int Id { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Site name is required.")]
[MinLength(6, ErrorMessage = "Name should be at least 6 characters.")]
public string SiteName { get; set; }
}
控制器。
[HttpPost]
public ActionResult Create(Configuration configItem)
{
if (ModelState.IsValid)
{
// do something.
}
return View("Index", configItem);
}
查看是
@model Models.SitesConfig.Configuration
@{
ViewBag.Title = "Sites Configurations";
}
<div>
@Html.ActionLink("Sites List", "List", "SiteConfig")
</div>
@using (Html.BeginForm("Create", "SiteConfig", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<fieldset>
<legend>New Satellitesite</legend>
<div>
@Html.LabelFor(m => m.SiteName, "Name")
@Html.TextBoxFor(m => m.SiteName)
@Html.ValidationMessageFor(m=>m.SiteName)
</div>
<br />
<input type="submit" value="Save" />
</fieldset>
}
请也建议我,如果有做验证的没有更好的办法。
Please also suggest me if there is any better way of doing the validations.
推荐答案
我不知道是什么问题。清理并生成应用程序之后,我能够看到错误消息。
I don't know what was the problem. After clean and build the application, I am able to see the error message.
谢谢,
纳雷什
Thanks, Naresh
这篇关于不显示MVC4验证错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文