- Enable client validation in web.config
<appSettings> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings>
2 The form
In your form you need to have a FormContext otherwise it will not generate validation attributes. If the FormContext is null we need to create a new FormContext like this in your view.
@{using (Html.BeginForm("Create", "Person", FormMethod.Post) { if (this.ViewContext.FormContext == null) { this.ViewContext.FormContext = new FormContext(); } // ..... }
3 Phrase validation attributes
Then after the ajax request we need to phrase validation attributes using JQuery like this,<br />
$.get("@Url.Action("Create", "Person")", null, function (data) { $('#yourDivId').html(data); $("form").removeData("validator"); $("form").removeData("unobtrusiveValidation"); $.validator.unobtrusive.parse("form"); });
Perfect!!! thanks.
ReplyDeleteWorking perfectly. Thank you
ReplyDelete