1

I have a regular application _Layout.cshtml and @RenderBody() to render all views inside, but only for the Login view need to be render as full page not inside @RenderBody().

Regards

tereško
  • 56,151
  • 24
  • 92
  • 147
Fernando.M
  • 157
  • 3
  • 9
  • 2
    Do you need just specify a different layout? Then see http://stackoverflow.com/q/5161380/67392 – Richard Nov 05 '14 at 13:39
  • In this way it got a error for @RenderBody(), I dont need a @RenderBody() in the other layout, it will be only a login screen, after user is logged it should back to the other layout. – Fernando.M Nov 05 '14 at 13:52

2 Answers2

4

You need to set the Layout property to null at the beginning of your view.

So, your Login.cshtml file should start with:

@model YourModel

@{
    Layout = null;
}
RePierre
  • 8,782
  • 2
  • 20
  • 35
3

You may not want to have no layout for your view. You probably want a custom layout (something like _LayoutFullPage.cshtml

<!DOCTYPE html>
<head>
    <title>SOMETHING HERE ALONG WITH OTHER HEAD ATTRIBUTES</title>
</head>
<body>
    @RenderBody() 
</body>
</html>

and then use that layout in the view with

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

Other options are to set the view as null in the cshtml (as suggested by RePierre) or to call return PartialView(model); within your controller.

AlexC
  • 10,146
  • 4
  • 34
  • 54