views:

26

answers:

1

Hi All

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  A: 

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 :)

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