用于对多个 MvcContrib 网格进行排序的控制器语法是什么?
我不太清楚对多个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从我的帖子中找出了我的问题:
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().