0

我主要将 MVCContrib 用于分页、排序和过滤方面。我的网格包含我们邮件列表应用程序中的所有地址(仅限后端)。用户可以删除、激活和停用列表成员,因此每行都有这些选项的操作链接。使用 jQuery,我正在捕获该单击并执行其他操作,例如显示操作完成通知。

因此,我遇到的问题是如何在执行这些操作后刷新网格以便用户可以看到结果?在删除时,我可以隐藏该行。当有人激活/停用电子邮件时,我该怎么办?只是使用jQuery来更新显示状态的表中的值?

// Activate the email address
$(".ActivateLink").click(function() {
    var id = $(this).attr("href");
    var i = id.indexOf("#");
    id = id.substring(i + 1);
    $.ajaxSetup({ 'async': false });
    $.post("/List/Activate", { "id": id }, function(data) {
        $(".message").text(data.message).addClass("notice");
    }, "json");
    return false;
});

我的控制器动作:

    //
    // POST: /List/Activate
    [HttpPost]
    public ActionResult Activate(int id)
    {
        string message = String.Empty;
        db.ActivateEventEmail(id, ref message);
        return Json(new { message = message });
    }

我的观点:

<%= Html.Grid(Model.EmailAddressList).Columns(column => {
    column.For("ImageActions").Named("").Sortable(false);
    column.For(a => (a.Email.Length > 30) ? String.Format("{0}...", a.Email.Substring(0, 30)) : a.Email).Encode(true).SortColumnName("Email").Named("Email Address");
    column.For(a => (a.ContactName.Length > 30) ? String.Format("{0}...", a.ContactName.Substring(0, 30)) : a.ContactName).Encode(true).SortColumnName("ContactName").Named("Contact Name");
    column.For(a => a.SignupDate).Named("Signup Date").Format("{0:d}").Attributes(@style => "text-align: right;");
    column.For(a => a.AccountStatus ? "Yes" : "No").SortColumnName("AccountStatus").Named("Active").Attributes(@style => "text-align: center;");
}).Sort(Model.GridSortOptions)
    .Attributes(@class => "table-list", style => "width: 100%;").RowAttributes(c => new MvcContrib.Hash(@class => "gridrow"))
%>
4

1 回答 1

0

好的,我想通了。

首先,我只需要添加一个对稍后将在代码中使用的函数的调用。

// Activate the email address
$(".ActivateLink").live('click', function() {
    var id = $(this).attr("href");
    var i = id.indexOf("#");
    id = id.substring(i + 1);
    $.ajaxSetup({ 'async': false });
    $.post("/List/Activate", { "id": id }, function(data) {
        refreshTable();
        $(".message").text(data.message).addClass("notice");
    }, "json");
    return false;
});

上面的控制器动作,我不碰,我上面的视图,我不碰。我创建的新javascript函数如下:

    function refreshTable() {
        $.ajaxSetup({
            async: false,
            cache: false
        });
        $.get('<%= Url.Action("Index", "List", new { filterText = Model.FilterText, filterActive = Model.FilterActive, filterGroup = Model.FilterGroup }) %>',
        function(response) {
            $(".table-list").replaceWith(response)
        });
    };

确保cache: false里面有。IE 喜欢从缓存中提取数据,真的把事情弄得一团糟。

在我的索引操作中,我从更改return View(emailListGrid);

        if (Request.IsAjaxRequest())
            return PartialView("EmailMaint", emailListGrid);
        else
            return View(emailListGrid);
于 2011-01-28T22:21:51.847 回答