Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of Razor Grammar of ASP.NET MVC

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the example analysis of ASP.NET MVC's Razor grammar, which is very detailed and has certain reference value. Friends who are interested must finish it!

1. Expression.

The expression must follow the "@" symbol

two。 Code block

The code block must be in "@ {}" and each line of code must end with ";". Variables defined in the code block may be used by other blocks in the same domain. For example, variables defined at the top of a view can be accessed by code blocks and snippets in the same view.

3. Overall Arrangement

Razor maintains consistency in the appearance and layout of web pages through layouts. The layout template contains basic labels and can specify the location of the rendered view contents. such as

Basic layout file (_ Layout.cshtml)

@ View.Title @ RenderSection ("Header"); @ RenderBody () @ RenderSection ("Footer")

After the layout page is defined, other view pages can reference the layout file, such as

@ {Layout= "~ / _ Layout.cshtml";} @ section Header {Page Header Content} @ section Footer {Copyright @ DateTime.Now.Year} Page Main Content

The pages are grouped together using the Razor layout and content view to show a complete page, each of which defines a different part of the page.

4. Partial view

Use the layout to achieve consistency in the appearance of the site by reusing part of the HTML code, but in some cases, the layout cannot be achieved, for example, a part of the information on the page needs to be repeated many times (consistent format, inconsistent display content), for example, the list of transactions on the page of the shopping site shows only the transaction name, current price and summary information.

ASP.NET MVC implements this requirement through the technology of partial views.

First, define a partial view and save it as a separate view file (for example, ~ / Views/Shared/Acution.cshtml).

@ model Auction

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report