asp.net-mvc – ValidationMessage仅适用于model和html属性 – MVC 3

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – ValidationMessage仅适用于model和html属性 – MVC 3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用MVC 3应用程序.

我需要添加一个类到验证消息html.我的意思是跨标签.

我的模特儿

[required(ErrorMessage = "Role Name is required")]
 [RegularExpression(@"^[a-zA-Z ]+$",ErrorMessage = "Only alphabets and spaces allowed")]
 public string RoleName { get; set; }

标记

<label for="name">RoleName</label>
  @Html.TextBoxFor(m => m.RoleName)
  @Html.ValidationMessageFor(m => m.RoleName,"some",new { @class = "immediate" })

But i could not see overloaded method like
@Html.ValidationMessageFor(m => m.RoleName,htmlAttributes) . if i
give some text,it is not showing my validaton message entered in
model. It always shows that some text only.

任何修复这个?

解决方法

你应该能够简单地传入null …

@ Html.ValidationMessageFor(m => m.RoleName,null,new {@class =“immediate”})

原文链接:https://www.f2er.com/aspnet/250146.html

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