Question

I'm refactoring all my partial views to use the leading underscore naming convention (didn't know about this convention when I got started, don't want to deviate from such a plain convention). But I've come across the generated (razor, C#) "Error.cshtml" view in \Views\Shared and I noticed it looks like it may be a partial view (no html / body tags) yet doesn't follow the convention:

@model System.Web.Mvc.HandleErrorInfo

@{
    ViewBag.Title = "Error";
}

<h2>
    Sorry, an error occurred while processing your request.
</h2>

I also notice it doesn't specify a Layout, yet sets the ViewBag.Title property as if it were going to be used by a Layout. What's the deal?

Was it helpful?

Solution

Strange. My generated Error.cshtml looks like a "normal" view with HTML body:

@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <title>Error</title>
</head>
<body>
    <h2>
        Sorry, an error occurred while processing your request.
    </h2>
</body>
</html>

I think in your case the layout is not set to null, hence the default layout will be used that contains the HTML wrapping elements. But it is still a "normal" view (not partial).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top