In MVC Application, I want to render some parts of form dynamically (which are like PartialView on Controller Side)
In the partial view, i dont have Html.BeginForm()
If you want the data validation tags to be there, you need to be in a FormContext
. Hence, if you're dynamically generating parts of your form, you need to include the following line in your partial view:
@{ if(ViewContext.FormContext == null) {ViewContext.FormContext = new FormContext(); }}
You then need to make sure you dynamically rebind your unobtrusive validation each time you add/remove items:
$("#form").removeData("validator");
$("#form").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse("#form");