用于对多个 MvcContrib 网格进行排序的控制器语法是什么?

发布于 2024-12-04 11:10:16 字数 1069 浏览 0 评论 0原文

我不太清楚对多个 MvcContrib 网格进行排序的语法。我知道 Jeremy Skinner 此处 的建议是使用 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

有什么想法吗?谢谢。

I can't quite figure out the syntax for sorting multiple MvcContrib grids. I know the recommendation from Jeremy Skinner here is to use the Bind attribute but I just can't get it right.

Here is my controller:

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

I guess I really don't understand everything about the Bind attribute. I tried adding a second GridSortOptions argument but that was not successful.

Here are my views if this helps.

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

Any ideas? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫性小仙女 2024-12-11 11:10:16

我从我的帖子中找出了我的问题:

MVCContrib Grid - Sort( GridSortOptions,前缀)不生成用于排序的链接

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

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

I figured out my problem from my post:

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

It is possible that the default binder is not pre-populating your parameters and so your GridSortoptions are probably null which means no links ultimately.

Also, just create a second GridSortOptions parameter for the second grid and use that in the call to Sort().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文