I'm working with Steve Sanderson's BeginCollectionItem utility to render a list of objects to be edited in MVC3, and it works great when you're rendering an entire collection from an iterator. My problem is coming when I'm trying to just add one new item to the collection, and return the html that represents that object. For some reason, my data annotations aren't being rendered in the html coming down from code.
Is there any fix available to this, or is there anything different, sans having to write the validation by-hand, that I can do to solve this issue?
Thanks.
Things to consider:
FormContext
exists in whatever method you are using to create this additional object. If you are using a partial view, add the following to it at the top:-
if (this.ViewContext.FormContext == null)
{
this.ViewContext.FormContext = new FormContext();
}
-
$("form").removeData("validator");
$("form").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse("form");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With