1. Mixed HTML and razor scripts
Knowledge Points: (1). cshtml How to reference Access data, (2). If for and HTML nesting
@using system.data@using CIIC. Tcp. entity;@{List<taut_menuentity>Menulist = (List<taut_menuentity>) session["Navigatemenu"];}<navclass= "Navbar-default navbar-static-side"role= "Navigation"> <Divclass= "Sidebar-collapse"> <ulclass= "NAV"ID= "Side-menu"> <Liclass= "Nav-header"> <Divclass= "Dropdown profile-element">@Html. ActionLink ("XXX Platform", ".. \\Login\\FirstPage ", new {id =" ", Loginuserid = Viewbag.loginuserid As String}, new {style =" Font-size:large;font-wei Ght:bold "})</Div> <Divclass= "Logo-element">in+</Div> </Li> <!--Permissions Menu Start -@if (menulist! = null) {foreach (taut_menuentity item in menulist) {if (item. level = = 1) {<Liclass=""> <ahref= "@item. Url "> <Iclass= "fa Fa-th-large"></I><spanclass= "Nav-label"data-i18n= "Nav.dashboard">@item. ModuleName</span><spanclass= "FA Arrow"></span> </a> <ulclass= "Nav nav-second-level collapse">@{List<taut_menuentity>submenulist = menulist.findall (t = = T.modulename = = Item. MenuName && t.level.value==2). (T=>t.orderid). ToList (); foreach (var subitem in submenulist) {<Liclass=""><ahref= "@subItem. Url">@subItem. MenuName</a></Li> } } </ul> </Li> } } } <!--Permission Menu End - </ul> </Div></nav>
2. Layout-related methods @RenderSection
Part One: Define the "submodule" placeholder to be inserted in _layout.cshtml
<type= "Text/javascript"> @RenderSection (" Headscript " false</script>
Section Two: defining the corresponding fill block in the xxx.cshtml
Headscript { function Del_comfire () { if (Confirm ("OK delete?")) { return true; } Else{this;}} }
3. Common methods in templates
@{ ViewBag. Xxx;}
@Url. Content ("Xxx") " //Generate only link text <href=" @Url. Content ("~/ Content/site.css ")" rel= "stylesheet" type= "text/css"/>< src = "@Url. Content ("~/scripts/jquery-1.4.4.min.js ")" Type = "Text/javascript"></script>
4.Html helper Methods
@Html. ActionLink ("Create New", "create")
< Li >@{html.renderaction ("Cartsummary", "ShoppingCart");} </ Li > //reference Partialviewresult
@{html.renderpartial("somepartial");//note with curly braces
@{ String message = "<strong>this is bold! </strong>";} < span >@Html.Raw(message)</span>
5.PartialViewResult Technology
Call the other controller and action in the template, return it to the result fill template, refer to the Html.renderaction () method
6. Parentheses syntax in a template
If you write directly @rootname.models there will be a compile error
//View cshtml The experimental code and Syntax phenomena @{ string rootname= "MyApp";} < span >@ (rootname). Models</span>
7.Razor Native href method 8.Switch condition to judge example 9.Razor template annotation syntax and template literal output 10.HTML encoding is @html. Raw () Method 11. JavaScript encoding is the @ajax.javascriptencode () method
ASP Razor Syntax and examples