Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ASP.NET MVC Baby Steps
Message
 
 
À
15/06/2013 12:18:53
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01576485
Message ID:
01576492
Vues:
36
>>Hi,
>>I am looking at the training video (Pluralsight) on APS.NET MVC Basics (produced in 2009) the demo project. The Views folder has Home folder and Shared folder. The Home folder is clear, it has view files for each view the project needs.
>>
>>The Shared folder has page Site.Master which is the master page used by all views.
>>
>>In the current version of VS 2012, when I create a test ASP.NET MVC project, the Shared folder has file _Layout.cshtml.
>>
>>What is the purpose of _Layout.cshtml?
>>
>>And does it mean that VS 2012 does not automatically create file Site.Master (master page for the project) and I have to create it manually?
>
>_Layout.cshtml is the razor equivalent of a master page. If it's created by VS then the content will vary depending on the type of project you create.
>Take this example (from Internet application which adds in a basic login functionality:
<!DOCTYPE html>
><html lang="en">
>    <head>
>        <meta charset="utf-8" />
>        <title>@ViewBag.Title - My ASP.NET MVC Application</title>
>        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
>        <meta name="viewport" content="width=device-width" />
>        @Styles.Render("~/Content/css")
>        @Scripts.Render("~/bundles/modernizr")
>    </head>
>    <body>
>        <header>
>            <div class="content-wrapper">
>                <div class="float-left">
>                    <p class="site-title">@Html.ActionLink("your logo here", "Index", "Home")</p>
>                </div>
>                <div class="float-right">
>                    <section id="login">
>                        @Html.Partial("_LoginPartial")
>                    </section>
>                    <nav>
>                        <ul id="menu">
>                            <li>@Html.ActionLink("Home", "Index", "Home")</li>
>                            <li>@Html.ActionLink("About", "About", "Home")</li>
>                            <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
>                        </ul>
>                    </nav>
>                </div>
>            </div>
>        </header>
>        <div id="body">
>            @RenderSection("featured", required: false)
>            <section class="content-wrapper main-content clear-fix">
>                @RenderBody()
>            </section>
>        </div>
>        <footer>
>            <div class="content-wrapper">
>                <div class="float-left">
>                    <p>© @DateTime.Now.Year - My ASP.NET MVC Application</p>
>                </div>
>            </div>
>        </footer>
>
>        @Scripts.Render("~/bundles/jquery")
>        @RenderSection("scripts", required: false)
>    </body>
></html>
Any views you create will, by default be slotted into the area defined by @RenderBody(). You'll also see things like the '@RenderSection("featured", required: false)' above. This says that there doesn't HAVE to be a 'featured' section in your view but, if there is, that's where it will go.
>
>This explains the basics pretty well :http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx

Thank you very much!
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform