我正致力于单页应用程序的错误处理和用户体验。我正在使用剃刀视图并将所有内容连接起来,但想要考虑任何可能性。如果传递给视图的模型没有预期值,则会抛出一般错误。
我希望能够将页面重新路由到更友好的错误页面,并提供有关该问题的一些细节,但是我无法找到一种方法来捕获它被发送到视图和试图加载它的页面。
我的问题是,有没有办法识别剃刀视图何时会发生此错误?如果是这样,我如何拦截它并重新路由到错误页面?
根据要求,编辑以显示控制器对象。
public ActionResult GetStoreRequests(string storeId, string storeName)
{
var requestListCustomRenderer = new RequestListCustomRenderer();
var storeRequestRenderedResult = new StoreRequestsRenderedResult();
var storeRequestResponse = _repository.GetStoreRequestInfo(storeId);
StoreRequestWithStoreName dto = _repository.GetStoreRequests(storeRequestResponse, storeId, storeName);
storeRequestRenderedResult.ChargeOffCount = dto.StoreRequestList.ChargeOffListRemovalList.Count();
storeRequestRenderedResult.ExtensionCount = dto.StoreRequestList.AgreementExtensionList.Count();
storeRequestRenderedResult.InventoryCount = dto.StoreRequestList.InventoryExchangeList.Count();
storeRequestRenderedResult.StoreId = dto.StoreId;
storeRequestRenderedResult.StoreName = dto.StoreName;
storeRequestRenderedResult.RenderedStoreRequests = requestListCustomRenderer.RenderStoreRequests(dto);
return PartialView("ApprovalView", storeRequestRenderedResult);
}
答案 0 :(得分:0)
您是否只想尝试/抓住您的PartialView
?
像这样:
try
{
PartialViewResult res = PartialView("ApprovalView", storeRequestRenderedResult);
return res;
}
catch (Exception ex)
{
return RedirectToAction("Error", "Home");
}