【发布时间】:2015-03-27 08:14:17
【问题描述】:
我遇到了一个关于在 MVC 4 中使用非侵入式验证插件进行客户端验证的问题。该验证适用于 TextBoxFor,但不适用于 TextAreaFor。我尝试使用 EditorFor 代替,但工具提示中没有出现验证(如图所示)。
型号
[Required]
[Display(Name = "New Message")]
[DataType(DataType.MultilineText)]
public string txtMessage { get; set; }
捆绑配置
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive-ajax.min.js",
"~/Scripts/jquery.validate.min.js",
"~/Scripts/jquery.validate.unobtrusive.min.js"));
查看
@using (Html.BeginForm("SaveBoardTaskMessage", "Task", FormMethod.Post, new { id = "BoardTaskMessageForm", enctype = "multipart/form-data" })){
@Html.TextAreaFor(model => model.txtMessage, new { @cols = 40, @rows = 6, @style = "font-family: inherit;resize: none;width:404px;" })
@Html.ValidationMessageFor(model => model.txtMessage)
}
【问题讨论】:
标签: jquery asp.net-mvc-4 validation client-side unobtrusive-validation