我有一个MVC索引ViewResult,它跨multip列搜索一个表。到目前为止,它已成功搜索了6列,但是由于某种原因,当我尝试添加另一列进行搜索时,得到的对象引用未设置为对象错误的实例。我已经浏览了许多与我在Stack Overflow上的问题类似的问题,但是所有解决方案都实现了我已经在使用的代码,并且我无法弄清楚为什么只有当我已经可以搜索倍数时添加新列时才会弹出此错误。列。
我的问题被标记为重复,尽管我表示我已经看过相关的Stack Overflow问题,但它们并不能解决我的问题。我的问题是我的代码所特有的,并且我没有发现任何问题要问同样的问题。
这是我能用的代码
if (String.IsNullOrEmpty(search))
{
employees = employees.OrderBy(x => x.pkDeviceUnderTest).Skip(defaSize * (pageIndex - 1)).Take(defaSize);
}
else
{
employees = employees.Where(s => s.pkDeviceUnderTest.ToString().Contains(search.ToUpper()) ||
s.nkPreEventTime.ToString().Contains(search) ||
s.nkHandleRating.ToString().Contains(search) ||
s.nkDeviceUnderTest.ToString().ToUpper().Contains(search.ToUpper()) ||
s.FaultApplication.nkFaultApplication.ToString().ToUpper().Contains(search.ToUpper()) ||
s.Firmware.nkFirmware.ToString().ToUpper().Contains(search.ToUpper()) ||
s.Hardware.nkHardware.ToString().ToUpper().Contains(search.ToUpper()))
.OrderBy(x => x.pkDeviceUnderTest)
.Skip(defaSize * (pageIndex - 1))
.Take(defaSize);
}
当我添加一行代码时,我得到了错误
if (String.IsNullOrEmpty(search))
{
employees = employees.OrderBy(x => x.pkDeviceUnderTest).Skip(defaSize * (pageIndex - 1)).Take(defaSize);
}
else
{
employees = employees.Where(s => s.pkDeviceUnderTest.ToString().Contains(search.ToUpper()) ||
s.nkPreEventTime.ToString().Contains(search) ||
s.nkHandleRating.ToString().Contains(search) ||
error here>>>>> s.nkNotes.ToString().ToUpper().Contains(search.ToUpper())||
s.nkDeviceUnderTest.ToString().ToUpper().Contains(search.ToUpper()) ||
s.FaultApplication.nkFaultApplication.ToString().ToUpper().Contains(search.ToUpper()) ||
s.Firmware.nkFirmware.ToString().ToUpper().Contains(search.ToUpper()) ||
s.Hardware.nkHardware.ToString().ToUpper().Contains(search.ToUpper()))
.OrderBy(x => x.pkDeviceUnderTest)
.Skip(defaSize * (pageIndex - 1))
.Take(defaSize);
}