当我运行网站时,我收到此错误:
System.InvalidOperationException:'Nullable对象必须有值。'
我有async function myFunc() {
const data = await request('http://......./', query);
const allData = data;
}
控制器,其中包含以下代码:
Duzenle
此行引发异常:
[Authorize(Roles = "Sube")]
public ActionResult Duzenle()
{
var date = DateTime.Now.Date;
var kullanici = UserGetter.GetUser();
var subeId = kullanici.SubeId.Value; // exception is thrown here
var kasaRaporu = db.KasaRaporu
.Where(kr => kr.SubeId == subeId).ToList()
.Where(kr => kr.Tarih.Date == date).FirstOrDefault();
if (kasaRaporu != null)
{
return View(kasaRaporu);
}
kasaRaporu = KasaRaporuCreator.Create(subeId);
return View(kasaRaporu);
}
有什么问题?
答案 0 :(得分:1)
显然kullanici.SubeId
是null
。当您尝试访问Value
可空的null
时,您将收到此异常。检查GetUser
方法,确保SubeId
在返回时不是null
。