Search code examples
ajaxasp.net-mvcajax.beginform

Update div using ajax.beginform inside asp mvc view


I want to show a success message after calling the following ajax.beginform from Index view

@using (Ajax.BeginForm("Insert", "Home", new AjaxOptions() { UpdateTargetId = "result", HttpMethod = "POST" }))
{
 @Html.TextAreaFor(m => m.openion)
}

this is my result div

<div id="result">
</div>

and my controller is

[Httppost]
public ActionResult InforMessage(openionModel usr)
    {
        return Content("Thanks for adding your openion");
    }

but when i try this it is going to another view InforMessage It is not updating the result div. There is no Informessage Exist. Still it open a new page with message "Thanks for adding your openion".How to solve this?


Solution

  • If your redirecting to another page its because you do not have the correct scripts loaded (or have duplicates or have them in the wrong order) so its doing a normal submit.

    Ensure you have included (in order)

    jquery-{version}.js
    jquery.unobtrusive-ajax.js