I have an action that returns a PartialView:
[ChildActionOnly]
public ActionResult TabInfo(int id, string tab)
{
ViewBag.Jobid = id;
ViewBag.Tab = tab;
var viewModel = _viewModelManager.GetViewModel(tab, id);
return
PartialView(string.Format("~/Views/{0}/Index.cshtml", tab), viewModel);
}
_viewModelManagerreturns a view from the Dictionary. If the user requests a tab that is not exsist, then an KeyNotFoundException will be thrown , but in my opinion, I get the following exception:
Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'
@using MyApplication.UI.Helpers.Html
@model MyApplication.UI.Models.MyJobModel
@{
ViewBag.Title = "Details";
}
<p>@Model.Blah</p>
...
*@ HttpException occurs here -- renders default error view *@
@Html.Action("TabInfo", new { id = ViewBag.Jobid, tab = ViewBag.Tab })
According to MS ...
The HandleErrorAttribute attribute in the child action method is ignored if an exception occurs in the child action itself. Therefore, the child action must handle its own exceptions. If the child action has an AuthorizeAttribute attribute, the attribute will execute and return the status code for unauthorized code 401.
[HandleError(ExceptionType = typeof(KeyNotFoundException), View="myError")] , try/catch, .
?
Bottomline: .