Enable client validation in Razor views (ASP MVC 3)

Viewed 70145

I try to add client side validation using this line of code:

@Html.EnableClientValidation()

But I keep getting this error message:

Compiler Error Message: CS1502: The best overloaded method match for 'Microsoft.WebPages.WebPageUltimateBase.Write(Microsoft.WebPages.Helpers.HelperResult)' has some invalid arguments

Is this working for anyone else, or is it another approach for this in ASP MVC 3?

5 Answers

Are you using the html <form> element on your page instead of Html.BeginFormto create your html FORM.

I had this exact same problem and worked out it was because the i was not using Html.BeginForm to create my FORM resulting in the required input attributes data-val-required="The Email field is required." data-val="true" class="input-validation-error and the place holder for the validation was not being injected into the page even though i had the @Html.ValidationMessageFor(m => m.User.Role) inserted on my view page.

Related