gsiradze
gsiradze

Reputation: 4733

asp.net MVC ajax does post back instead of render partial view in my div

I have this code written in my index.cshtml

@Ajax.ActionLink("First", "First", new AjaxOptions()
{
    HttpMethod = "GET",
    UpdateTargetId = "partialstest",
    InsertionMode = InsertionMode.Replace
})

@Ajax.ActionLink("Second", "Second", new AjaxOptions()
{
    HttpMethod = "GET",
    UpdateTargetId = "partialstest",
    InsertionMode = InsertionMode.Replace
})

<div id="partialstest" style="width: 500px; height:500px; border:1px solid red;">

</div>

<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/additional-methods.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/5.2/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>

and it's my controller:

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

    public PartialViewResult First()
    {

        return PartialView("Partial1");
    }

    public PartialViewResult Second()
    {

        return PartialView("Partial1");
    }

when i'm debugging it here's a link:

http://localhost:23166/switchPartial/Index

when i'm clicking on my link (first or second) i want that my partial view render in div which id is partialstest. But instead it does post back and goes in

http://localhost:23166/switchPartial/First

why?

Upvotes: 3

Views: 706

Answers (1)

sachin
sachin

Reputation: 2361

Check if files MicrosoftAjax.js and MicrosoftMvcAjax.js are really present in ../../Scripts folder. For MVC3 and higher, make sure you are using jquery.unobtrusive-ajax.js.

Upvotes: 1

Related Questions