目前,我有一位控制员,他们采取了多项行动,但我已陷入了一个问题,采取单一行动,似乎要求在行动本身内对存放处进行即时处理,否则,在日常行动期间,我会得到一种“不尊重”,而行动本身似乎与控制者的其他行动不同。 这是我迄今为止所做的:
public class PatentController : Controller
{
IRepositoryExtension patentRepository;
public PatentController()
{
PatentRepository patentRepository = new Proj.Data.PatentRepository();
}
//Constructor for unit test project
public PatentController(IRepositoryExtension repository)
{
patentRepository = repository;
}
public ActionResult Index()
{
return View();
}
//Other actions removed for brevity
public ActionResult DetailsPartial(string id)
{
//If this PatentRepository is removed, NullReferenceException occurs
PatentRepository patentRepository = new Proj.Data.PatentRepository();
USPTOPatent usptoPatent = patentRepository.GetPatent(id);
return PartialView("DetailsPartial", usptoPatent);
}
是否有特别理由,为什么我需要在行动中立即储存库,以便其工作? 如果我说:
反对不指标的。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
资料来源:
Line 155: //PatentRepository patentRepository = new Proj.Data.PatentRepository(); Line 156: USPTOPatent usptoPatent = patentRepository.GetPatent(id); Line 157:
return PartialView("DetailsPartial", usptoPatent); Line 158: }