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 に答える