我收到一个错误,我不知道如何解决?它声称发生在:
var respondents = RespondentRepository.GetRespondents(UserSession, fieldsToInclude).Where(r=>r.Email.Contains(query)).ToList();
当我删除所有 .Where 东西时,它似乎工作正常。我真的不习惯这个错误,所以我不确定最好的开始在哪里?
错误:
System.NullReferenceException: Object reference not set to an instance of an object.
代码:
MakeSafeRequest(() =>
{
var respondents = RespondentRepository.GetRespondents(UserSession, fieldsToInclude).Where(r=>r.Email.Contains(query)).ToList();
model = new RespondentSearchViewModel
{
Respondents = respondents,
TableData = respondents.SelectToListOrEmpty(r =>
{
return new TableRowViewModel
{
Id = r.Id,
Data = new Dictionary<string, string>
{
{ "FirstName", r.FirstName },
{ "LastName", r.LastName },
{ "EmailAddress", r.Email },
{ "Project", r.ProjectId.ToString() },
{ "Status", r.RecruitingStatus.ToIconHtml() },
{ "ViewHistory", "<div class=\"btnBlue btSml\"><a class=\"closeMe\" href=\"/RespondentSearch/RespondentDetails/?respondentId="+r.Id +"\" >view detail</a></div>"}
//{ "StatusDate", r.LastActionDate.Value.ToLocalTime().ToString() },
}
};
})
};
});
模型:
public class RespondentSearchViewModel:ListPageViewModel
{
public List<Respondent> Respondents { get; set; }
}