当我尝试对JQGrid值进行排序时,我发现NullReferenceException未被用户代码异常处理。
public ActionResult GetSearch(string sidx, string sord, int page, int rows)
{
if (sidx != "")
{
//In the Session["ResourceSearch"] I have loaded the values
DataContractClass[] SortResult = Session["ResourceSearch"] as DataContractClass[];
//Sort the JQGrid value from input 'sidx'
SortResult = SortResult.OrderBy(p => p.GetType().GetProperty(sidx).GetValue(p, null)).ToArray() as DataContractClass[];
//Load data here
}
}
只有当int属性作为sidx
的输入时才会遇到问题。但是如果sidx
的任何字符串属性没有问题。我能够对数据进行排序。
答案 0 :(得分:2)
或者:
p
在lambda中为空sidx
p
我的猜测是第二次。
检查实际上是否存在名称等于抛出此异常时的值sidx
的公共属性。顺便说一句 - 这基本上就是消息框中的第二个帮助字符串告诉你的事情。