I am facing an issue regarding the client side validation using unobtrusive Validation plugin in MVC 4. The validation works fine with TextBoxFor but it is not working with TextAreaFor . I have tried using EditorFor instead but not getting validation appear in the tooltip ( As given in the image ).
Model
[Required]
[Display(Name = "New Message")]
[DataType(DataType.MultilineText)]
public string txtMessage { get; set; }
Bundle Config
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive-ajax.min.js",
"~/Scripts/jquery.validate.min.js",
"~/Scripts/jquery.validate.unobtrusive.min.js"));
View
@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)
}
Try to replace TextAreaFor
with EditorFor
. Since your model already has the multiline flag set, this should not impact your UI, but it should work around a potential (and past documented for some versions) bug with TextAreaFor
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.