client site validation not workinghttp://forums.asp.net/t/1783389.aspx/1?client+site+validation+not+workingThu, 22 Mar 2012 16:15:34 -040017833894892510http://forums.asp.net/p/1783389/4892510.aspx/1?client+site+validation+not+workingclient site validation not working <p>If I use the script below, client side Validation doesn't work, but server side does</p> <p></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Html.LabelFor(model =&gt; model.Name)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;span class=&quot;editor-field&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Html.TextBox(&quot;CategoryTextFieldBridges[0].TextFields.Name&quot;, null, new { @class = &quot;text-box single-line&quot; })<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Html.ValidationMessage(&quot;CategoryTextFieldBridges[0].TextFields.Name&quot;)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/span&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/p&gt;&nbsp;</p> <p></p> <p>however if I use</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;p&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Html.LabelFor(model =&gt; model.CategoryTextFieldBridges[0].TextFields.Name)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;span class=&quot;editor-field&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Html.EditorFor(model =&gt; model.CategoryTextFieldBridges[0].TextFields.Name)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Html.ValidationMessageFor(model =&gt; model.CategoryTextFieldBridges[0].TextFields.Name)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/span&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/p&gt;&nbsp;</p> <p></p> <p>Client side validation does work, they both product the same HTML, so why isn't the first example working the client side validation?</p> 2012-03-22T00:55:41-04:004892828http://forums.asp.net/p/1783389/4892828.aspx/1?Re+client+site+validation+not+workingRe: client site validation not working <p>You need to use <em><strong>@Html.TextBoxFor</strong></em> to bind textbox with the model's field. Doing that will also enforce client-side validation if any specified within model.</p> <p>@Html.TextBox does not bind text box with the model property (i.e. field), and thus, validation not firing up in first case.</p> 2012-03-22T06:05:25-04:004892903http://forums.asp.net/p/1783389/4892903.aspx/1?Re+client+site+validation+not+workingRe: client site validation not working <p>Did you added below 2 keys in web.config</p> <pre class="lang-cs prettyprint"><pre class="prettyprint">&lt;add key=&quot;ClientValidationEnabled&quot; value=&quot;true&quot; /&gt; &lt;add key=&quot;UnobtrusiveJavaScriptEnabled&quot; value=&quot;true&quot; /&gt;</pre></pre></pre> 2012-03-22T06:49:16-04:004894099http://forums.asp.net/p/1783389/4894099.aspx/1?Re+client+site+validation+not+workingRe: client site validation not working <p></p> <blockquote><span class="icon-blockquote"></span> <h4>dharnendra</h4> <p></p> <p>Did you added below 2 keys in web.config</p> <pre class="prettyprint">&lt;add key=&quot;ClientValidationEnabled&quot; value=&quot;true&quot; /&gt; &lt;add key=&quot;UnobtrusiveJavaScriptEnabled&quot; value=&quot;true&quot; /&gt;</pre> <p></p> </blockquote> Yes checked and done <p></p> 2012-03-22T15:57:59-04:004894127http://forums.asp.net/p/1783389/4894127.aspx/1?Re+client+site+validation+not+workingRe: client site validation not working <p></p> <blockquote><span class="icon-blockquote"></span> <h4>nirman.doshi</h4> <p></p> <p>You need to use <em><strong>@Html.TextBoxFor</strong></em> to bind textbox with the model's field. Doing that will also enforce client-side validation if any specified within model.</p> <p>@Html.TextBox does not bind text box with the model property (i.e. field), and thus, validation not firing up in first case.</p> <p></p> </blockquote> Thanks, sorted I need to change the name of the form element to get everything to submit as one&nbsp; cascading model, but I can use @Html.TextBoxFor(model =&gt; model.CategoryTextFieldBridges[0].TextFields.Name, new { Name = &quot;CategoryTextFieldBridges[0].TextFields.Name&quot; }) <p></p> 2012-03-22T16:15:34-04:00