MVC 3 unobtrusive verification - conditionally disable / enable verification

I have a form that has the ability to enter measurements for:

  • Width and height
  • Width
  • Height

And I have two div containers that I hide / show depending on which of the three options is selected:

<div class="editor-field" id="width-container">
     @Html.EditorFor(model => model.Width)
     @Html.ValidationMessageFor(model => model.Width)
</div>

<div class="editor-field" id="height-container">
     @Html.EditorFor(model => model.Height)
     @Html.ValidationMessageFor(model => model.Height)
</div>

, , , , , data- * . CustomAttribute , , jquery, , . , 0 , , , .

EDIT:

, , "" , , , div : none

+5
2

jQuery, , :

jQuery.validator.defaults.ignore = ":hidden";

// the line above is outside any $(document).ready(...) or similar
$(document).ready(function(){
    ...
});
...
+12

, , ( Google, , "" ):

fooobar.com/questions/898759/...

.

$("#height-container input[type='text']").attr("disabled", "disabled");

.

+1

All Articles