Question

My ajax is not enabled.

When I press on an ajax Link, the page posts to a partial page.

What is wrong in my code ?

I am using Visual Studio 2013 express MVC4

View

  @{
        ViewBag.Title = "Home Page";
    }

    @Ajax.ActionLink("link", "Test", new AjaxOptions { 
    HttpMethod="POST",
    UpdateTargetId="t",
    InsertionMode=InsertionMode.Replace
    })
    <div id="t">mmmmmmmmmmmmmmmmmm</div>

Controller

    public PartialViewResult Test ()
    {

        return PartialView("_PTest");
    }

    public ActionResult Index()
    {
        return View();
    }

Partial View

<p>partial test</p>

_LayOut

  @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/bootstrap")
Was it helpful?

Solution

You need to ensure Unobtrusive Ajax is referenced. It should be present at the point of creating a new MVC project but if you need details to get it from Nuget, take a look here https://www.nuget.org/packages/jQuery.Ajax.Unobtrusive/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top