行アクションを実行した後、MVCCONTRIBグリッドを更新します
-
26-10-2019 - |
質問
私は主にページング、ソート、フィルタリングの側面に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"))
%>
解決
さて、私はこれを理解しました。
まず第一に、私は後でコードを下回る関数に呼び出しを追加する必要がありました。
// 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);
所属していません StackOverflow