PureKrome / WorldDomination.Web.Mvc.ErrorHandling

13 stars 6 forks source link

_ViewStart.cshtml should be used for error view layout #8

Open darrylwhitmore opened 11 years ago

darrylwhitmore commented 11 years ago

Per this StackOverflow answer, my understanding is that my error views (404.cshtml, etc) should pick up the standard _ViewStart.cshtml and thus be rendered within my _Layout.cshtml like all my other views, but this is not working.

If I add the contents of _ViewStart.cshtml to my error view manually, I do get my error view rendered within my _Layout.cshtml as expected:

@model WorldDomination.Web.Mvc.ErrorViewModel

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@{
    ViewBag.Title = "401";
}

<h2>401</h2>

Looking at the error views in the sample project, I see they are written as full HTML documents, but this goes against the rest of the Asp.Net MVC convention. Instead, error views should pick up _ViewStart.cshtml (if present).

Here is a suggested fix to CustomErrorHandlingModule.RenderCustomErrorView(). Pass in true instead of false for the runViewStartPages value:

var view = new RazorView(controllerContext, viewPath, null, true, null);