Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 719
Dave Alperovich Avatar asked Feb 19 '23 09:02

Dave Alperovich


1 Answers

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.

like image 127
VJAI Avatar answered May 23 '23 02:05

VJAI