Client-side validation for non-editor form (and not using XForms)?


Anyone know if there is a recommended way to do client-side validation for a form presented to a non-edit-mode user?  Also not using XForms...

I've been trying to get the classic MVC unobtrusive validation to work but the HTML coming from Html.EditorFor(m => m.FieldName) does not spit out the correct annotations needed by those libraries (data-val, data-val-required, etc).  I assume Episerver has removed those so that it doesn't interfere with Editor-mode validation.  Does anyone know how to turn that back on without having to write out the attributes manually?

Using the latest version of Episerver 7.1.  Here's an example of my view & controller:


[Required(ErrorMessage = "Name is required.")]
public string Name { get; set; }


@using (Html.BeginForm()) 
        @Html.LabelFor(m => m.Name)  
        @Html.ValidationMessageFor(m => m.Name)  
        @Html.EditorFor(m => m.Name)
    <input type="submit" value="Submit" class="btn"/>


Many thanks,


Oct 02, 2013 0:10

Think I just answered my own question.  In web.config under appSettings add:

<add key="ClientValidationEnabled" value="true" />

<add key="UnobtrusiveJavaScriptEnabled" value="true" />

Seems to work!  Hopefully won't break Edit mode.

Oct 02, 2013 0:39

If you are worried that your settings in web.config might interfere with EPiServer UI, you could remove these settings on specific paths:

For example

<location path="EPiServer">
  <remove key="ClientValidationEnabled" />


Oct 02, 2013 14:05

Thank you!  This is really helpful.

Oct 02, 2013 15:44
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.