mvc Ajax. BeginForm cannot be refreshed asynchronously, or switched to a new page, or because the page is refreshed (or a solution), mvcajax. beginform

Source: Internet
Author: User mvc Ajax. BeginForm cannot be refreshed asynchronously, or switched to a new page, or the page is refreshed.

I made an afternoon of Ajax yesterday. beginForm failed to Implement Asynchronous refresh, and the returned data was always submitted to a new page. I searched for n methods on the Internet, but I asked n people to solve the problem. This is the first day of the year, I was surprised to find the problem.

Layout page:


<div id="upload-body">    <div id="returnData"><script type="text/ecmascript">    function Reload(data) {        alert(data);    }    function DisplayError(data) {        alert(data);    }</script>
Introduce jquery. unobtrusive-ajax.js: <script src = "~ /Scripts/jquery. unobtrusive-ajax.js "> </script>


[HttpPost]        public JsonResult Index(Models.TestModels.TestModel testModel)        {            return Json("Hi,"+testModel.UserName, JsonRequestBehavior.AllowGet);        }

Then there is a problem:

After submission:

This is not the expected result. The good result is that the page will not be refreshed or jump to the page. Then start to look up the problem and see if jquery. unobtrusive-ajax.js is referenced,

I did reference it, and I went online to find it. I did not have any resources available. I tried all kinds of methods and still did not solve the problem. Alas, is it Ajax. beginForm only has its own name in vain. In my heart, I am quietly swearing: % $ junk % $! # ¥ %...

Failed to return last night.

I came to the company this morning and opened it with Chrome again. I was surprised to find that:

In an instant, I felt a little furious and excited. Is it because of this? No, are you sure you have referenced it?

After carefully observing the last and third images, we were surprised to find that jquery was behind jquery. unobtrusive-ajax,


The original reference of _ Layout. cshtml is at the bottom. Hey hey, so I decided to directly put the reference of jquery. unobtrusive-ajax after jquery,

Run again:


Haha, the effect is really good. Suddenly, I can't help but have a great reverence and admiration for Ajax. BeginForm. It's really a waste!


Conclusion: Pay attention to the reference sequence of jQuery and other js.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.