Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have you considered using unobtrusive validation?</p> <p>You say you are using MVC3 (although not the Razor view engine apparently).</p> <p>With your code like this: <code>&lt;p&gt;&lt;label for="ClientName"&gt;ClientName:&lt;/label&gt; &lt;%= Html.TextBoxFor(model =&gt; model.Name)%&gt;&lt;/p&gt;</code> which could be written as <code>&lt;p&gt;@Html.LabelFor(model=&gt;model.Name) @Html.TextBoxFor(model =&gt; model.Name) &lt;/p&gt;</code> in Razor syntax.</p> <p>If you put this in your web.config:</p> <pre><code>&lt;appSettings&gt; &lt;add key="ClientValidationEnabled" value="true" /&gt; &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt; &lt;/appSettings&gt; </code></pre> <p>and then decorate the property in your model with something like this data annotation:</p> <pre><code>[Display(Name = "Name")] [Required(ErrorMessage = "Name is required")] public string Name { get; set; } </code></pre> <p>Then by adding the following into your <code>_Layout.cshtml</code> file you will get unobtrusive validation to work:</p> <pre><code>&lt;script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>Then you could add this somewhere on the page (where you want the validation message to be shown): <code>@Html.ValidationMessageFor(model=&gt;model.Name)</code></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