user1238784
user1238784

Reputation: 2440

Create a Master Page in MVC Core application

I promise I am complete newbie to MVC Core (I have only 1 week practice) I know how to add a master page to a Dot net framework but not to MVC Core. Can anyone help me? Thanks

Upvotes: 2

Views: 5487

Answers (2)

Ramil Mammadov
Ramil Mammadov

Reputation: 532

You should add _Layout.cshtml to /Views/Shared folder

Upvotes: 0

Mr. Roshan
Mr. Roshan

Reputation: 1805

Layout Page Structure (Layout1.cshtml)

<!DOCTYPE html>  
<html>  
<head>  
    <meta name="viewport" content="width=device-width" />  
    <title>@ViewBag.Title</title>  
@RenderSection("head", false)  
</head>  
<body>  

     @Html.ActionLink("Home", "Index", "My") |   
     @Html.ActionLink("AboutUs", "AboutUs", "My") |   
     @Html.ActionLink("ContactUS", "ContactUS", "My") |   
     @Html.ActionLink("Facebook", "Facebook", "My") |   
     @Html.ActionLink("Twitter", "Twitter", "My")  

    <br />  
        @RenderBody()  
    <br />  

    Hello Nitin Pandit…………This is the demo of Layout pages.  

</body>  
</html> 

Set the Layout Page of your view when creating of your action method view

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

Upvotes: 6

Related Questions