asp.net-mvc – 将类应用于@ Html.ValidationMessageFor

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 将类应用于@ Html.ValidationMessageFor前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
模型:
[required(AllowEmptyStrings = false,ErrorMessage="Please enter student name.")]
[StringLength(20,ErrorMessage="Student name cannot be over 20 characters long")]
    public string StudentName { get; set; }

视图:

@Html.ValidationMessageFor(m=>m.StudentName,new {@class = "validation"})

好像ValidationMessageFor没有这样的重载.我如何申请课程?

解决方法

我只是看了 this.

所以在你的情况下尝试:

@Html.ValidationMessageFor(m=>m.StudentName,""/* or null or what you want the error message to be */,new { @class = "validation" })
原文链接:https://www.f2er.com/aspnet/248084.html

猜你在找的asp.Net相关文章