Dave Alperovich
Dave Alperovich

Reputation: 32500

want to put @renderbody() into a partial view source by _layout

Creating an MVC 3 Razor project. have a very involved UI design. I wanted to put @renderbody() into a partial view source by _layout. The compiler won't let me. Is there a way to do this?

Upvotes: 4

Views: 3930

Answers (1)

VJAI
VJAI

Reputation: 32768

Instead of partial view you can go for master/sub layouts.

MasterLayout.cshtml

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>@ViewBag.Title</title>
</head>
<body>
  @RenderBody()
</body>
</html>

Layout.cshtml

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

// html code above render body
@RenderBody()
// html code below render body

Your sublayout(Layout.cshtml) contains the code that should be in the partial view.

Upvotes: 8

Related Questions