How can you return a partial view from a controller and inject it into a specific section of the page using an AJAX form?
How can you return a partial view from a controller and inject it into a specific section of the page using an AJAX form?
Student
The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
Returning a partial view from a controller and injecting it into a specific section of the page using an Ajax.BeginForm is a common pattern in ASP.NET MVC for dynamic content updates without reloading the whole page.
Ajax.BeginForm)PartialViewfrom the controllerUpdateTargetIdController Code
Notes:
_SuccessMessage.cshtmland_FormPartial.cshtmlare partial views (no layout).ActionResult, returningPartialView(...).Client-Side View Code (Razor)
Required Scripts:
Partial View Example:
_SuccessMessage.cshtmlOptional JavaScript Callbacks
End-to-End Flow
id="formContainer"viaUpdateTargetIdTips & Gotchas
jquery.unobtrusive-ajax.jsis loaded after jQuery_Layout.cshtml)UpdateTargetIdmust match the DOM element where you want to inject