Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
584 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...