我收到一个错误,对象引用未设置为对象的实例我尝试了多种方法,但一直收到该错误,此代码行发生错误
@if(!string.IsNullOrWhiteSpace(Model.profile.photo))
{
@Html.DisplayFor(x => x.profile.firstname) @Html.DisplayFor(x => x.profile.lastname)
}
else {
<p>This user does not have a profile</p>
}
@if(!string.IsNullOrWhiteSpace(Model.profile.photo))
我有一个包含 2 个模型的视图
public class relist_profile
{
public relisting relisting { get; set; }
public profile profile { get; set; }
}
我的控制器是
public ActionResult detail(int id)
{
relisting relistings = db.relistings.Find(id);
var profiles = (from s in db.profiles where s.registrationID == relistings.RegistrationID select s).FirstOrDefault();
return View(new relist_profile {profile = profiles, relisting = relistings });
}
发生的情况是,当var 配置文件不匹配时(s.registrationID != relistings.RegistrationID) ,它会抛出错误,但如果有一个 PROFILE 并且它匹配(TRUE),那么一切正常。我该如何解决这个问题