1、_LayOut.cshtml File for mvc Layout file for , What's in it htm Static files for , As mvc other view The basic master of , Sub view or call it just in page setup @{Layout=null;} that will do , Now for some of the grammar inside to explain :

@RenderBody() This layout is used by default for all pages (WebForm The template of ), It can only be called once on a page , Son view You can share resources with them, such as js、css etc. ;

@RenderPage("url") It is equivalent to a place where all the contents of the page are rendered by the engine . For example, the fixed head of a web page can be placed in a shared view file , Then call... From the layout page through this method , Usage is as follows :@RenderPage("~/Views/Shared/_Header.cshtml")

  @RenderSecion("scripts",required:true|false) This placeholder represents : A section in the page will be rendered here ( It can be html The code can also be c# Code and Html The combination of ). Parameters url Represents the name of the section rendered on the subpage ,required Represents the declaration of whether the node must appear in the subpage , If it is set to true If the sub page does not contain this node, an error will be reported . If we want to use the default section on the master page, we can make the following judgment :

@if(IsSectionDefined("sectionName"))

{

@RenderSection("sectionName")

}  else   {

<span> Default section </span>

}

If the sub page has this section, we will render the sub page's , If not, our default Html block ( for example : The head of the website , Bottom , Sidebar, etc ).

Basic grammar

@using : Introduce namespace

  1. @model: Declare strongly typed data Model type
  2. @section: Define the section information to implement the master page
  3. @RenderBody(): When creating a view based on this layout page , The content of the view is merged with the layout page , The content of the newly created view will be displayed through the @RenderBody() Methods are rendered between tags .
  4. @RenderPage: Render a page . For example, the fixed head of a web page can be placed in a shared view file , Then call... From the layout page through this method , Usage is as follows :
  5. @RenderPage("~/Views/Shared/_Header.cshtml")
  6. @RenderSection: The layout page also has sections (Section) The concept of , It is convenient for local presentation

Code block :

@{ Code block }

@if ( Conditions ) { Code block }

@switch ( Conditions ) { Branches match code blocks }

@for ( Cycle control ) { Code block }

@foreach ( Cycle control ) { Code block }

@while ( Cycle control ) { Code block }

@do { Code block } while ( Cycle control ) 『 The code in the code block should be strictly in accordance with c# Syntax to , There must be a semicolon at the end of each line 』

Reference to external documents

  1. @Scripts.Render("url") ;
  2. @Styles.Render("url");

stay Razor If you need to let your own class have intelligent prompt function under the engine , Just add your own class's namespace to view/webconfig Of <pages><namespaces> Under the node .

stay mvc4.0 Use in URLHelper and HTMLHelper It feels very practical , such as Use @Html.Actions("ViewName","ControllerName",new {params}); More than traditional stitching url More convenient , The relative path calculation error is avoided ;

MVC4 relevant Razor More related articles on grammar

  1. MVC4 relevant Razor Grammar and Form Forms

    Razor Layout (Layout) All the projects built by default come with one _ViewStart.cshtml file , The code in the file is as follows : @{ Layout = "~/Views/Shared/_Layou ...

  2. MVC4 relevant Razor Grammar and Form Forms ( Reprint )

    Razor Layout (Layout) All the projects built by default come with one _ViewStart.cshtml file , The code in the file is as follows : @{ Layout = "~/Views/Shared/_Layou ...

  3. Talking about RSA encryption algorithm

    One . What is asymmetric encryption 1. The encrypted key is not the same as the encrypted key , Such an encryption algorithm is called asymmetric encryption 2. The key is divided into : Public key , Private key   Public key : A password that can be encrypted and decrypted to anyone , Is an open Private key : The public key can be generated from the private key , But from ...

  4. Talking about DES encryption algorithm

    One .DES Encryption algorithm 1. The key must be 8 Bytes , namely 64bit length 2. Because the key is byte[8] , Representing strings can also be invisible bytes , It can be done with Base64 Coding algorithms are used together 3. encryption . Decryption takes bytes ...

  5. Talking about URLEncoder Coding algorithm

    One . Why use URLEncoder When the client makes a web page request , The URL may contain non ASCII Content in code form , Such as Chinese . It is not allowed to put Chinese in the web address directly , So we need to use URLEncoder Code address , take ...

  6. Talking about Hex Coding algorithm

    One . What is? Hex The content of hexadecimal representation of each byte , Use a string to display . Two . effect Will not be visible , Complex byte array data , Convert to displayable string data Be similar to Base64 Coding algorithm difference :Base64 Turn three bytes into ...

  7. Talking about Base64 Coding algorithm

    One . What is codec code : Using specific algorithms , Process the original content , Generate the content after the operation , Form another form of data representation , According to the algorithm , And back again , This operation is called encoding . decode : Using the inverse of the algorithm used in coding , For the encoded ...

  8. Talking about kubernetes service Those things ( Part 1 )

    One . problem First , So let's think about this : visit k8s In the cluster pod, The client needs to know pod Address , Need perception pod The state of . So how to get all the pod The address of ? If one node Upper pod fault , How the client perceives ? Two .k8 ...

  9. Talking about kubernetes service Those things ( The next part )

    Welcome to Netease cloud community , Learn more about netease technology product operation experience . 5、 ... and .K8s 1.8 New characteristics --ipvs ipvs And iptables The difference in performance As the number of services grows ,IPTables Rules will multiply , The problem is that ...

Random recommendation

  1. database MySQL Installation diagram

    MySQL Installation diagram One .MYSQL Installation 1. Open the download mysql The installation files , Double-click on the run mysql-5.5.40-win32.msi. 2. Choose the installation type , Yes "Typical( Default )". ...

  2. 10 strip PHP Programming habits help you find a job

    The past few weeks have been quite a complicated experience for me . Our company has made a lot of layoffs , I'm one of them , But I experienced the joy boring . I've never been fired , So it's hard not to think too much . I started browsing the recruitment section , A full-time PHP The position of programmer is very attractive , ...

  3. Win10 preservation Element To the album

    Save control to album private async void saveImg_Click(object sender, RoutedEventArgs e) { StorageFolder savedPics ...

  4. Array API

    1. Array creation var arrayObj = new Array();// Create a default array , The length is 0 var arrayObj = new Array(size);// Create a size An array of lengths , Be careful ...

  5. Porter/Duff, Mask the picture setColorFilter

    Published in http://avenwu.net/2015/02/03/porterduff Fork on github https://github.com/avenwu/support I often meet someone who gives me ...

  6. opencv Learning notes ( 6、 ... and ) Histograms compare image similarity

    opencv Learning notes ( 6、 ... and ) Histograms compare image similarity opencv Provides API To compare the similarity of the pictures , Make it easy for us to 2 Two pictures to compare , This is the histogram comparison , This is histogram, The principle is that ...

  7. Ubuntu 16.04 LTS (Xenial Xerus)

    Canonical Just officially released Ubuntu 16.04 LTS (Xenial Xerus), This is a long-term support version , The government will provide up to 5 Years of technical support ( Including general updates /Bug Repair / Security upgrade ), Until 2021 ...

  8. contrast AMD 890、AMD 880、 AMD 790、AMD 785、 AMD 780、AMD 7

    770 No set display . The middle and low end are the mainstream . 780G With set display . Now you can ignore . 785G Now it's the mainstream of band display . 790GX High end with integrated display . 790FX High end , No set display . 790X With set display . Basically ignore . 870 Big board , No set display 88 ...

  9. Windows 7 The configuration JDK Environment variables and Java Environment variable configuration

    Let's talk about it Java Environment variable configuration , Is in Windows 7 The configuration JDK environment variable . Method / step   1 install JDK, During installation, you can customize the installation directory and other information , For example, we choose the installation directory as :C:\Program Fil ...

  10. win2012 Add architecture to FTP The server

    open IIS Manager (win+R Input inetmgr Back in or through add to FTP Site