我有一个 MVC4 互联网应用程序,其中包含用于创建用户帐户的表单。表单验证有效,但当输入验证失败时,不显示错误消息。它仍然阻止提交,直到验证问题解决但没有文本
剃刀视图表格
<h2>Create New Account</h2>
<fieldset>
<legend></legend>
@using (Html.BeginForm("CreateUser",null)){
@Html.AntiForgeryToken()
<table class="create">
<tr>
<td colspan="2"><b>New Account</b>
</tr>
<tr>
<td>@Html.DisplayNameFor(model=>model.UserName)</td><td>@Html.TextBoxFor(model=>model.UserName)</td>
<td>@Html.DisplayNameFor(model=>model.EmailAddress)</td><td>@Html.TextBoxFor(model=>model.EmailAddress)</td>
<td><input type="submit" value="Create User" /></td>
</tr>
</table>
}
</fieldset>
@Html.ValidationSummary()
使用的捆绑包包括验证文件
bundles.Add(new ScriptBundle("~/bundles/asset").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui-{version}.js",
"~/Scripts/jquery.validate*",
"~/Scripts/jquery.unobtrusive*"));
使用的模型是实体模型,我添加了一个部分类来注释验证要求
[MetadataType(typeof(UserProfileMetadata))]
public partial class UserProfile
{
//Empty Class just required for adding class level attribute
}
public class UserProfileMetadata
{
//Fields from user profile requiring annotations
[EmailAddress]
[Required]
[Display(Name = "Email Address")]
public string EmailAddress { get; set; }
[Required]
public string UserName { get; set; }
}
验证工作但现在显示消息让我认为它一定是标记错误,但我看不到它。