필터링 및 정렬에 grid.mvc (http://gridmvc.codeplex.com/)를 사용하고 있습니다. 아무도 액션 컨트롤러에서 필터링 된 결과를 처리하는 방법을 알고 있습니까? FormCollection을 통해 숨겨진 필드를 전달하려고하지만 페이징의 원인이 보이는 값만 전달됩니다. 아니면 mvc에서 필터 및 정렬 및 MVCController있는 작업에 대한 필터링 된 결과를 사용할 수있는 좋은 대안 눈금이 무엇입니까?grid.mvc 사용 필터링 된 결과 컨트롤러
_customersGrid.cshtml
@using GridMvc.Html
@using GridMvc.Site.Models
@using GridMvc.Sorting
@model GridMvc.Site.Models.Grids.CustomersGrid
@{
ViewBag.Title = "_CustomersGrid";
}
<h2>_PersonsGrid</h2>
@Html.Grid(Model).Named("customersGrid").Columns(columns =>
{
columns.Add(o => o.CustomerID)
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(o => Html.Hidden("CustomerID", o.CustomerID));
columns.Add(o => o.CompanyName)
.Titled("Name")
.SetWidth(110);
columns.Add(o => o.Phone)
.Titled("Phone")
.SetWidth(250);
}).WithPaging(15).Sortable().Filterable().WithMultipleFilters()
Index.cshtml
@{
ViewBag.Title = "Home";
}
@using (Html.BeginForm(null, null, FormMethod.Post, new { @class = "form-horizontal" }))
{
<fieldset>
<legend></legend>
@Html.Action("Grid") @* grid in a partial view *@
<p>
@Html.ActionLink("Back", "Index",null,new { @class = "btn", @accesskey="b" })
<button type="submit" class="btn btn-primary" accesskey="s" ><u>S</u>ave</button>
</p>
</fieldset>
}
HomeController 작업
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index( FormCollection form)
{
var filterSettings = Session["grid-filters"] as IGridFilterSettings;
var url = new UriBuilder(Url.Action(null, null, null, Request.Url.Scheme));
if (filterSettings != null)
url.Query = GetGridFilterQueryString(filterSettings); //restore grid filter settings
/* How to get the filtered values from grid insteat from formcollection*/
var chckedValues = form.GetValues("CustomerId");
foreach (var id in chckedValues)
{
//Do something
Debug.WriteLine(id);
};
ViewBag.ActiveMenuTitle = "Demo";
return Redirect(url.ToString());
}
public ActionResult Grid()
{
var repository = new CustomersRepository();
var grid = new CustomersGrid(repository.GetAll());
Session["grid-filters"] = grid.Settings.FilterSettings;//store grid filters in the session
return PartialView("_CustomersGrid", grid);
}
당신은 당신의보기에서 코드의 일부를 표시 할 수 그리드와? –
보이는 항목과 보이지 않는 항목을 모두 포함하는보기 모델이 있습니까? –