繁体   English   中英

不干扰的验证不适用于MVC 4中的Textarea

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM