如何为此编写 MVC2 验证
我的视图页面中有这段代码。
<td>
Mandate Name:
</td>
<td>
<%= Html.TextBox("MandateName")%>
</td>
我为此名称编写了 MVC2 Validation。
像这样的东西。
//[Validator(typeof(MandateValidator))]
[MetadataType(typeof(Mandate_Metadata))]
public partial class Mandate {
public class Mandate_Metadata
{
[StringLength(250, ErrorMessage = "Mandate name cannot exceed 250 characters!")]
[Required(ErrorMessage = "Mandate Name Required!")]
public string MandateName { get; set; }
[StringLength(3000, ErrorMessage = "Description cannot exceed 3000 characters!")]
public string MandateDescription { get; set; }
}
}
但我的验证在这个领域不起作用,任何人都可以帮助我,我在这里做错了什么吗? 谢谢
I have this code in my view page.
<td>
Mandate Name:
</td>
<td>
<%= Html.TextBox("MandateName")%>
</td>
I wrote MVC2 Validation for this name.
something like this.
//[Validator(typeof(MandateValidator))]
[MetadataType(typeof(Mandate_Metadata))]
public partial class Mandate {
public class Mandate_Metadata
{
[StringLength(250, ErrorMessage = "Mandate name cannot exceed 250 characters!")]
[Required(ErrorMessage = "Mandate Name Required!")]
public string MandateName { get; set; }
[StringLength(3000, ErrorMessage = "Description cannot exceed 3000 characters!")]
public string MandateDescription { get; set; }
}
}
but some how my validation is not working on this field could any body help me what's wrong I am doing here?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经有一段时间没有使用 MVC 了,但是,我相当确定你错过了验证消息。IE 类似的东西
也在你的 using 语句中的表单顶部引用,你需要
It has been a while since I have played with MVC, however, I'm fairly certain you are missing your validation message.. IE something like
Also cited at the top of your form inside of your using statement, you need
你有类似的
看法吗?
查看 SottGu 的 帖子使用 mvc2 进行模型验证。
do you have anything like
in your view?
Check out SottGu's post on Model Validation with mvc2.