Ajax Action Link不会更新div

时间:2014-05-16 19:04:24

标签: ajax asp.net-mvc

这是我在索引视图中的示例代码:

@model IEnumerable<GridViewTest.Models.TabelaModel>

<script src="~/Scripts/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>

<div id="tabela">
    <table>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Druzyna)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.LiczbaMeczy)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.LiczbaGoliStrzelonych)
            </th>
            <th></th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Druzyna)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LiczbaMeczy)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LiczbaGoliStrzelonych)
            </td>
            <td>
                @Ajax.ActionLink("Edit", "Edit", new { id=item.ID }, new AjaxOptions() {HttpMethod = "GET", UpdateTargetId = "tabela", InsertionMode = InsertionMode.Replace})
            </td>
        </tr>
    }
    </table>
</div>

当有人点击“编辑”ajax动作链接时,我的意图是替换div“tabela”内容,但是当我这样做时,我正在重定向到“编辑”视图。 “编辑”视图是局部视图。

控制器:

public ActionResult Index()
    {
        string grupa = "a";

        if (TempData["grupa"] != null)
        {
            grupa = TempData["grupa"].ToString();
        }
        else
        {
            grupa = "B";
        }

        string query = "Select * From LigaMistrzowGrupy where Grupa = @Grupa";
        List<TabelaModel> tabela = tabelaFunckje.wczytajTabele(query, grupa).ToList();

        return View(tabela);
    }

 [HttpGet]
    public PartialViewResult Edit()
    {
        return PartialView("_GridViewTabelaEdit");
    }

你能说出我做错了什么吗?我是MVC的新手。

1 个答案:

答案 0 :(得分:0)

将jquery.unobtrusive-ajax.js或jquery.unobtrusive-ajax.min.js添加到您的页面(以及jquery)。 它是一个可用的金块包。

相关问题