javascript - Conditionally unobtrusive validation mode -


i'm developing asp.net mvc 5 application razor, c# , .net framework 4.7.

i want disable input fields on table depending on model's property value. did javascript:

if ($('#lawid').val() === "1") {      $('#productstable').attr("disabled", true);     $('.addlevelbutton').attr("disabled", true);     $('.deletelevelbutton').attr("disabled", true); } 

this works don't know how disable unobtrusive validation. razor view is:

<td>     <div class="group">         @html.textboxfor(m => m.products[index].name, new { @class = "productclass" })<br />         <div class="mensajeerror">@html.validationmessagefor(m => m.products[index].name)</div>     </div> </td> <td>     <div class="group">         @html.textboxfor(m => m.products[index].description, new { @class = "productclass", @style = "max-width:none" })<br />         <div class="mensajeerror">@html.validationmessagefor(m => m.products[index].description)</div>     </div> </td> <td>     <div class="group">         @html.textboxfor(m => m.products[index].comment, new { @class = "productclass" })<br />         <div class="mensajeerror">@html.validationmessagefor(m => m.products[index].comment)</div>     </div> </td> <td>     <div class="group">         @html.checkbox(string.format("delete_{0}", index))     </div> </td> 

this html generated fields want hide (all of them inside productstable table).

<div class="group">     <input data-val="true" data-val-number="the field id must number." data-val-required="the id field required." id="products_0__id" name="products[0].id" type="hidden" value="0" />     <input data-val="true" data-val-number="the field law must number." data-val-required="the law field required." id="products_0__law" name="products[0].law" type="hidden" value="1" />     <input data-val="true" data-val-length="must 14 characters long" data-val-length-max="14" data-val-length-min="14" data-val-required="product&#39;s code requiered" id="products_0__productcode" name="products[0].productcode" type="number" value="" />     <div class="mensajeerror"><span class="field-validation-valid" data-valmsg-for="products[0].productcode" data-valmsg-replace="true"></span></div> </div> 

searching have found helper @{ html.enableclientvalidation(false); } don't know how use , haven't found complete example.

i did conditional in razor view show input file:

@if (model.lawid == 1) {     <input name = "chinacodes" id = "chinacodes" class="upload" type="file"> } 

do have same each field or can globally fields @ once?

i've done adding @ beginning of @body section:

@section body {     @if (model.lawid == 1)     {         html.enableclientvalidation(false);         html.enableunobtrusivejavascript(false);     }      [ ... ] } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -