views:

211

answers:

1

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?

+7  A: 

You can, instead, use the following in place of the expected line of code.

@(ViewContext.ClientValidationEnabled = true)

Probably an oversight in the extension methods for htmlhelper.

Update now with answer goodness

Actually, you can use the HtmlHelper method by doing the following

@{ Html.EnableClientValidation(); }
BuildStarted
Thank you for your response, but when I put your line of code into the view all it does is output `True` into the page. Do I have to place the code anywhere special? Now im placing it just above my `@using(Ajax.BeginForm(...`
Martin
Strange, I didn't notice that before, thanks :)
BuildStarted
The reason it doesn't work with just @ is because @ expects to write something to the browser but EnableClientValidation doesn't return anything so Microsoft.WebPages.WebPageUltimateBase.Write fails as a result
BuildStarted
Ok, I guess that works. I did not get my client side validation to fire, but that might be because of something else.
Martin
Hmm...well, first I say check the source of your page to be sure the validation JS is being output. (I'm sure it is but it's always something to check) Then make sure you have @Html.ValidationMessageFor(m => m.Property) so the validation message knows where to go.
BuildStarted
Thx, I had forgotten the validation message. Works now!
Martin