我似乎在使用 Child Actions 吞下很多异常。
[ChildActionOnly]
[OutputCache(Duration = 1200, VaryByParam = "key;param")]
public ActionResult ChildPart(int key, string param)
{
try
{
var model = DoRiskyExceptionProneThing(key, param)
return View("_ChildPart", model);
}
catch (Exception ex)
{
// Log to elmah using a helper method
ErrorLog.LogError(ex, "Child Action Error ");
// return a pretty bit of HTML to avoid a whitescreen of death on the client
return View("_ChildActionOnlyError");
}
}
我觉得我正在剪切和粘贴成堆的代码,每次剪切粘贴我们都知道一只小猫正被天使的眼泪淹没。
是否有更好的方法来管理子操作中的异常,以允许屏幕的其余部分正确呈现?