Helo, 我正在開發ASP.NET MVC 3應用程序。ASP.NET MVC 3使用升序,降序選項自定義排序WebGrid
我有一個觀點
var grid = new WebGrid(rowsPerPage: 10, ajaxUpdateContainerId: "GridDiv",canPage: true,canSort: true);
grid.Bind(source: Model);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(htmlAttributes: new { id="grid" },
columns: grid.Columns(
grid.Column("Name"),
grid.Column("Age"),
grid.Column("Sex")
)
在控制器我有一個自定義排序算法對數據進行排序。 我有一個自定義升序排序和自定義降序排序。
我希望當用戶點擊列標題來按照我自定義的排序算法對行進行排序而不是在一個版本中進行排序。
對於我嘗試以下(我走「sortdir」,並相應地處理它)
控制器
public ActionResult Persons(string sortdir)
{
PersonsListModel = GetAllPersonsList();
if(sortdir=="ASC")
return View(MyAscendingCustomSortAlgorithm(PersonsListModel));
else
return View(MyDescendingCustomSortAlgorithm(PersonsListModel));
}
MyAscendingCustomSortAlgorithm
和MyDescendingCustomSortAlgorithm
是返回我的自定義算法排序列表功能。
當頁面加載列表排序正確,但是當我點擊標題的排序是亂了up.I調試,一切工作正常。
我的問題是我怎麼能作出這樣的工作,並且仍然保持正確的尋呼
我也試着設置canSort: false
但我不能在標題點擊了。
非常感謝您的任何幫助
http://stackoverflow.com/questions/5413069/header-format-for-webgrid這應該有助於初學者:) – Yasser 2012-04-09 06:45:52