【问题标题】:What is the controller syntax for sorting multiple MvcContrib Grids?对多个 MvcContrib 网格进行排序的控制器语法是什么?
【发布时间】:2011-09-14 15:43:24
【问题描述】:

我不太明白排序多个 MvcContrib 网格的语法。我知道 Jeremy Skinner here 的建议是使用 Bind 属性,但我就是无法正确使用。

这是我的控制器:

public ActionResult Index([Bind](Prefix="grid1")GridSortOptions sort)\\how do I reference the prefix of my second grid?
{
  ViewData["sort"] = sort;
  var products = _productService.GetAllProducts();
  var categories = _categoryService.GetAllCategories();

  //Here is where I am stuck
  if(sort.Column != null)
   {
     products = products.OrderBy(sort.Column, sort.Direction);
     //how do I reference the sort columns of my second grid?
   }

  var model = new ContainerModel
              {
                Products = products,
                Categories = categories
              };

  return View(model);
}

我想我真的不了解 Bind 属性的所有内容。我尝试添加第二个 GridSortOptions 参数,但没有成功。

如果这有帮助,这是我的看法。

.Sort((GridSortOptions)ViewData["sort"], "grid1")//Grid 1
.Sort((GridSortOptions)ViewData["sort"], "grid2")//Grid 2

有什么想法吗?谢谢。

【问题讨论】:

  • 这有什么好运气吗?我也有类似的问题。

标签: asp.net-mvc-3 mvccontrib mvccontrib-grid


【解决方案1】:

我从帖子中发现了我的问题:

MVCContrib Grid - Sort(GridSortOptions, prefix) not generating links for sorting

默认绑定器可能没有预先填充您的参数,因此您的 GridSortoptions 可能为 null,这意味着最终没有链接。

另外,只需为第二个网格创建第二个 GridSortOptions 参数,然后在调用 Sort() 时使用它。

【讨论】:

  • 这可能有助于其他人知道要使其工作,您需要为要在同一页面上排序的每个网格设置一个前缀。如:.Sort((GridSortOptions)ViewData["fooSort"],"foo")
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-22
  • 1970-01-01
  • 2016-12-14
  • 1970-01-01
  • 2011-09-28
  • 1970-01-01
相关资源
最近更新 更多