user3527150
user3527150

Reputation: 926

Using ajax.actionlink in mvc4 causes to refresh the page

I have a view like this:

@model IEnumerable<DomainClasses.Class>

@{
    ViewBag.Title = "لیست ";
}
<div id="test">
<h2>لیست کلاس ها</h2>

<p>
    @Html.ActionLink("ایجاد کلاس جدید", "Create")
</p>
<table>
    <tr>
        <th>
           @Html.DisplayNameFor(model => model.ClassName)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ClassName)
        </td>
        <td>
            @*@Html.ActionLink("ویرایش", "Edit", new { id=item.Id }) |*@
            @Ajax.ActionLink("ویرایش1","Edit",new { id=item.Id },new AjaxOptions(){UpdateTargetId = "test",InsertionMode = InsertionMode.Replace,HttpMethod = "GET"})
            @Html.ActionLink("حذف", "Delete", new { id=item.Id })
        </td>
    </tr>
}

</table>
    </div>

As you can see I created a div named test, and I make an ajax action link:

  @Ajax.ActionLink("ویرایش1","Edit",new { id=item.Id },new AjaxOptions(){UpdateTargetId = "test",InsertionMode = InsertionMode.Replace,HttpMethod = "GET"})

So when I click on the link that I created by ajax actionlink my page is refreshed and my url changed to localhost/Class/Edit/1. Why does this happen? I thought my page shouldn't be refreshed!

Best regards

Upvotes: 1

Views: 684

Answers (1)

milagvoniduak
milagvoniduak

Reputation: 3254

Make sure that you have jquery.unobtrusive-ajax.js script included on your view. If you don't here is the nuget package http://www.nuget.org/packages/jQuery.Ajax.Unobtrusive/2.0.20710. When you install the package make sure that jquery.unobtrusive-ajax.js is included in your view.

Upvotes: 1

Related Questions