Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.Net MVC EnableClientValidation doesn't work
    text
    copied!<p>I want as well as Client Side Validation as Server Side Validation. I realized this as the following:</p> <p>Model: ( The model has a DataModel(dbml) which contains the Test class )</p> <pre><code>namespace MyProject.TestProject { [MetadataType(typeof(TestMetaData))] public partial class Test { } public class TestMetaData { [Required(ErrorMessage="Please enter a name.")] [StringLength(50)] public string Name { get; set; } } } </code></pre> <p>Controller is nothing special.</p> <p>The View:</p> <pre><code>&lt;% Html.EnableClientValidation(); %&gt; &lt;% using (Ajax.BeginForm("Index", "Test", FormMethod.Post, new AjaxOptions {}, new { enctype = "multipart/form-data" })) {%&gt; &lt;%= Html.AntiForgeryToken()%&gt; &lt;fieldset&gt; &lt;legend&gt;Widget Omschrijving&lt;/legend&gt; &lt;div&gt; &lt;%= Html.LabelFor(Model =&gt; Model.Name) %&gt; &lt;%= Html.TextBoxFor(Model =&gt; Model.Name) %&gt; &lt;%= Html.ValidationMessageFor(Model =&gt; Model.Name) %&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;div&gt; &lt;input type="submit" value="Save" /&gt; &lt;/div&gt; &lt;% } %&gt; </code></pre> <p>To make this all work I added also references to js files:</p> <pre><code>&lt;script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>Eventually it has to work, but it doesnt work 100%: It does validates with no page refresh after pressing the button. It also does "half" Client Side Validation. Only when you type some text into the textbox and then backspace the typed text. The Client Side Validation appears. But when I try this by tapping between controls there's no Client Side Validation.</p> <p>Do I miss some reference or something? (I use Asp.Net MVC 2 RTM)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload