0

I am trying to use validations with ASP.NET MVC 2. I am just validating a textbox value. Below is my approach. Create View -:

<%: Html.ValidationSummary(true)%> 
<%: Html.TextBoxFor(model => model.Name, new { @class="input-standard"})%>
<%: Html.ValidationMessageFor(model => model.Name) %>

Model Property-:

[Required (ErrorMessage="Name Required")]

public virtual string Name { get; set; }

But if i keep the textbox empty and click on submit then still the ModelState.IsValidate prperty is returning true.

Please suggest what am i doing wrong.

Thanks.

1
  • Have you put a breakpoint before the ModelState.IsValid call to determine that the value is null or an empty string? Commented Oct 1, 2010 at 14:10

1 Answer 1

1

Have you added <% Html.EnableClientValidation(); %> and a reference to the Microsoft MVC ajax validation javascript (MicrosoftMvcAjax.js and MicrosoftMvcValidation.js).

Edit: sorry just noticed this does not answer your question :)

Sign up to request clarification or add additional context in comments.

1 Comment

Yes...I have added <% Html.EnableClientValidation(); %> and reference to MicrosoftMvc refrences too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.