[英]unobtrusive Validation not working for Textarea in MVC 4
我遇到有關在MVC 4中使用不顯眼的Validation插件進行客戶端驗證的問題。該驗證可與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)
}
嘗試用EditorFor
替換TextAreaFor
。 由於您的模型已經設置了多行標志,因此這不會影響您的用戶界面,但應該可以解決TextAreaFor
的潛在錯誤(某些版本已經過記錄)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.