Update div using ajax.beginform inside asp mvc view

本小妞迷上赌 提交于 2019-12-28 02:18:10

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/32369838/update-div-using-ajax-beginform-inside-asp-mvc-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!