Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 0.49 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ASP.NET MVC Unobtrusive validation - why form context is needed?
  2. @model MyViewModel
  3. @{
  4.     ViewContext.FormContext = new FormContext();
  5. }
  6.  
  7. @Html.LabelFor(x => x.Foo)
  8. @Html.EditorFor(x => x.Foo)
  9. @Html.ValidationMessageFor(x => x.Foo)
  10.        
  11. success: function(result) {
  12.     // we are replacing only a portion of the form
  13.     $('#somePartOfTheForm').html(result);
  14.  
  15.     $('form').removeData('validator');
  16.     $('form').removeData('unobtrusiveValidation');
  17.     $.validator.unobtrusive.parse('form');  
  18. }