2011-09-14 33 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。 –