我已经在我的aspx视图页面下面的代码:MVC验证不工作在Web窗体项目
<% using (Html.BeginForm())
{
%>
<div>
CustomerCode:
<%= Html.TextBoxFor(x=> x.CustomerCode) %>
<%= Html.ValidationMessageFor(x => x.CustomerCode)%>
这个代码在我的模型:
public class MyModel
{
[Required(ErrorMessage="customer code req")]
[StringLength(2,ErrorMessage="must be 2 u idiot")]
public string CustomerCode {get; set;}
但如果我输入2个以上在文本框和charachters提交页面,在控制器,当我做:
if (ModelState.IsValid)
它总是说,它有效吗?我错过了什么?我已经把这个MVC项目放在一个Web Forms项目中,但是MVC项目工作正常,只是验证不起作用,有什么想法?谢谢。
感谢,但我已经这样做了,它仍然说这是有效的,当它显然不是! :( – Lisa 2010-07-13 13:55:40