Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

asp.net mvc - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...