2011-01-28 2 views
0

주로 페이징, 정렬 및 필터링 측면에서 MVCContrib를 사용하고 있습니다. 내 표에는 메일 링리스트 응용 프로그램의 모든 주소가 포함됩니다 (백엔드에만 해당). 사용자는 목록 구성원을 삭제, 활성화 및 비활성화 할 수 있으므로 각 행에 이러한 옵션에 대한 작업 링크가 있습니다. jQuery를 사용하여 클릭을 캡처하고 작업 표시 알림과 같은 다른 작업을 수행합니다.행 작업을 수행 한 후 MVCContrib Grid 새로 고침

이 문제로 인해 사용자가 결과를 볼 수 있도록 이러한 작업을 수행 한 후에 그리드를 새로 고치는 방법은 무엇입니까? 삭제시 행을 숨길 수 있습니다. 어떤 사람이 이메일을 활성화/비활성화 할 때 무엇을 할 수 있습니까? 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")) 
%> 

답변

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; 
}); 

위의 컨트롤러 동작은 내가 건드리지 않고 위의 견해와 접촉하지 않습니다.

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는 캐시에서 데이터를 가져 와서 정말 엉망이되는 것을 좋아합니다. 내 색인 작업에

나는

 if (Request.IsAjaxRequest()) 
      return PartialView("EmailMaint", emailListGrid); 
     else 
      return View(emailListGrid); 
+0

그래서 당신은 클라이언트와 서버 사이 사이를 네 번째 전체 그리드를 보내려면 어떻게합니까에 return View(emailListGrid); 변경? 나는 그리드에 새로운 행을 추가하기를 원한다는 것을 제외하고는 당신과 같은 배에있다. 그래서 내 "refreshTable"방법은 전체 그리드를 교체하는 대신 응답에서 모델을 추가합니다. – Buzzer

+0

예, 전체 그리드가 전송됩니다. MVCContrib 테이블에 행을 추가하는 방법을 모르겠습니다. –