Is there a tutorial or code example of using Ajax.BeginForm
within Asp.net MVC 3 where unobtrusive validation and Ajax exist?
This is an elusive topic for MVC 3, and I cannot seem to get my form to work properly. It will do an Ajax submit but ignores the validation errors.
Example
//In Model
//In PartailView //PartailView.cshtml
In Index.cshtml view
In Controller
you must be pass ViewName and Model to RenderPartialViewToString method. it will return you view with validation which are you applied in model and append the content in "targetId" div in Index.cshtml. I this way by catching RenderHtml of partial view you can apply validation.
Ajax forms work asynchronously using Javascript. So it is required, to load the script files for execution. Even though it's a small performance compromise, the execution happens without postback.
We need to understand the difference between the behaviours of both Html and Ajax forms.
Ajax:
Won't redirect the form, even you do a RedirectAction().
Will perform save, update and any modification operations asynchronously.
Html:
Will redirect the form.
Will perform operations both Synchronously and Asynchronously (With some extra code and care).
Demonstrated the differences with a POC in below link. Link