使用 LINQ to MySQL (DbLinq) 和动态 LINQ 的可排序 JqGrid - Orderby 不起作用
我在 JqGrid 中排序条目时遇到问题。 Orderby 似乎不起作用。我在代码中设置了断点,我注意到 orderby 不会改变元素的顺序。知道可能出什么问题吗?
我正在使用 LINQ to SQL 和 MySQL(DbLinq 项目)。
我的操作代码:
public ActionResult All(string sidx, string sord, int page, int rows)
{
var tickets = ZTRepository.GetAllTickets().OrderBy(sidx + " " + sord).ToList();
var rowdata = (
from ticket in tickets
select new {
i = ticket.ID,
cell = new String[] {
ticket.ID.ToString(), ticket.Hardware, ticket.Issue, ticket.IssueDetails, ticket.RequestedBy, ticket.AssignedTo, ticket.Priority.ToString(), ticket.State
}
}).ToArray();
var jsonData = new
{
total = 1, // we'll implement later
page = page,
records = tickets.Count(),
rows = rowdata
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
I've got problem with sorting entries in JqGrid. Orderby seem to not work. I set breakpoint in code and I noticed, that orderby doesn't change order of elements. Any idea what could be wrong?
I'm using LINQ to SQL with MySQL (DbLinq project).
My action code:
public ActionResult All(string sidx, string sord, int page, int rows)
{
var tickets = ZTRepository.GetAllTickets().OrderBy(sidx + " " + sord).ToList();
var rowdata = (
from ticket in tickets
select new {
i = ticket.ID,
cell = new String[] {
ticket.ID.ToString(), ticket.Hardware, ticket.Issue, ticket.IssueDetails, ticket.RequestedBy, ticket.AssignedTo, ticket.Priority.ToString(), ticket.State
}
}).ToArray();
var jsonData = new
{
total = 1, // we'll implement later
page = page,
records = tickets.Count(),
rows = rowdata
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用以下内容
这里我假设您的票证对象的类型是
Ticket
。Try with the following
Here I suppose that the type of your ticket object is
Ticket
.tickets
变量是有序的,但随后您将其用作另一个未排序的查询的源,因此它的顺序不确定。您希望在第二个 LINQ 查询上使用 orderby。The
tickets
variable is ordered, but then you use that as the source for another query which is NOT ordered so it's order is undetermined. You want the orderby on the second LINQ query.