2011-09-14 41 views
0

我不能完全弄清楚排序多个MvcContrib网格的语法。我知道Jeremy Skinner here的建议是使用Bind属性,但我无法正确理解。排序多个MvcContrib网格的控制器语法是什么?

这里是我的控制器:

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

我想我真的不理解的绑定属性的一切。我尝试添加第二个GridSortOptions参数,但没有成功。

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

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

任何想法?谢谢。

+0

还有什么运气呢?我也有类似的困境。 –

回答

1

我从后想通了我的问题:

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

这可能是默认的粘合剂没有预先填充您的参数,所以你GridSortoptions可能是零,这意味着没有任何联系,最终。

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

+1

对于其他人来说可能会有帮助,因为要使其工作,您需要为每个要在同一页面上排序的网格设置一个前缀。如下:'.Sort((GridSortOptions)ViewData [“fooSort”],“foo”)' – LOAS

+0

好点LOAS。 –

相关问题