Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

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

Open
darrylwhitmore opened this issue Oct 23, 2013 · 0 comments
Open

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

darrylwhitmore opened this issue Oct 23, 2013 · 0 comments

Comments

@darrylwhitmore
Copy link

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);
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant