更新时间:2023-02-14 17:19:08
全部文章在:http://yassershaikh.com/mvc-3-web-grid-sorting-not-working/
使用COLUMNNAME属性的帮助,我用错了列名,因为它的排序是行不通的。
下面是code我现在使用
< DIV ID =网格>
@ {
//添加ajaxContainerId
VAR listgrid =新的WebGrid(来源:Model.ABC,rowsPerPage:2,ajaxUpdateContainerId:网格); @ listgrid.GetHtml( 列:listgrid.Columns(
listgrid.Column(头:COLNAME,COLUMNNAME =DbColName,格式为:@<文本>< A HREF =JavaScript的:ShowData(@ item.ColName);> @ item.Name< / A> < /文本>中canSort:真)
listgrid.Column(NULL,删除,(项目)=> MvcHtmlString.Create(的String.Format(< A HREF ='DeleteList / {0}>删除< / A>中,@ item.Name ))),
))
}
< / DIV>
希望这可以帮助别人的未来呢!
I am using MVC 3 with Razor and I am using the below web grid to show some data,
What I need sorting on my first column. I have used similar code on other pages too for my sorting and it works fine, but here it doesnt seem to work.
However if I go to the next page say page 2 and now I click sort, it is sorted ascending and then again same problem.
<div id="grid">
@{
// added ajaxContainerId
var listgrid = new WebGrid(source: Model.ABC, rowsPerPage: 2, ajaxUpdateContainerId: "grid");
@listgrid.GetHtml(
columns: listgrid.Columns(
listgrid.Column("ColName", format: @<text><a href="javascript:ShowData(@item.ColName);">@item.Name</a></text>, canSort:true),
listgrid.Column(null, "Delete", (item) => MvcHtmlString.Create(string.Format("<a href='DeleteList/{0}'>Delete</a>", @item.Name))),
))
}
</div>
Full article at : http://yassershaikh.com/mvc-3-web-grid-sorting-not-working/
using the columnName attribute helped, I was using the wrong column name, because of which the sorting was not working
Here is the code I am using now
<div id="grid">
@{
// added ajaxContainerId
var listgrid = new WebGrid(source: Model.ABC, rowsPerPage: 2, ajaxUpdateContainerId: "grid");
@listgrid.GetHtml(
columns: listgrid.Columns(
listgrid.Column(header:"ColName", columnName="DbColName", format: @<text><a href="javascript:ShowData(@item.ColName);">@item.Name</a></text>, canSort:true),
listgrid.Column(null, "Delete", (item) => MvcHtmlString.Create(string.Format("<a href='DeleteList/{0}'>Delete</a>", @item.Name))),
))
}
</div>
Hope this helps someone in future too!