Ajax.BeginForm not working asynchronously

I am using Ajax.BeginFrom in Index view to test method in Home controller

@using (Ajax.BeginForm(actionName: "TestMethod",
        controllerName: "Home",
        ajaxOptions: new AjaxOptions
        {
            HttpMethod = "POST",
            InsertionMode = InsertionMode.Replace,
            UpdateTargetId = "TestInfo",
            LoadingElementId = "Progress"
        }))
{
    <input type="submit" value="Search" />
    <div id="TestInfo"></div>
}

      

and

[HttpPost]
public virtual ActionResult TestMethod()
{
    return Content("ok");
}

      

But after submitting, redirecting the page to / Home / TestMethod and showing 'ok'.

I added

<add key="UnobtrusiveJavaScriptEnabled" value="true" />

      

in webconfig and

<script src="@Links.Scripts.jquery_unobtrusive_ajax_min_js" type="text/javascript"></script>

      

in my layout. But it still doesn't work asynchronously. Where is the problem?

+3


source to share


1 answer


when it almost always happens because your script files are not loading, see below post:

http://completedevelopment.blogspot.com/2011/02/unobstrusive-javascript-in-mvc-3-helps.html



Set the specified flag in the web.config file:

  • Include link to jQuery library ~ / Scripts / jquery-1.4.4.js

  • Include a link to a library that intercepts this magic in ~ / Scripts / jquery.unobtrusive-ajax.js

                     

+6


source







All Articles