10-1 슈퍼 심 플 뷰 엔진 sshtml 보기 엔진(낸 시 공식 문서 번역)
Nuget 을 따로 사용 하지 않 아 도 됩 니 다.이 엔진 은 낸 시의 메 인 프로그램 집합 에 내장 되 어 있 으 며,사용 중 자동 으로 조립 되 어 직접 사용 할 수 있 습 니 다.이 엔진 은 처리 할 수 있다.
sshtml
, html
or htm 。
Models can either be standard types, or
ExpandoObjects
(or, in reality, any other object implementing IDynamicMetaObjectProvider
that implements IDictionary<string, object>
to access its properties). All commands have an optional semi-colon delimiter which can be used to remove ambiguity. Any
[.Parameters]
parameter can be multiple levels deep (e.g. This.Property.That.Property
). As SSVE is a regular expression based view engine there is no “code execution”, so you cannot specify an arbitrary chunk of your own code to execute. The built in syntax/commands that you can use are as follows.
Please note that all quotes should be single-quotes in the expressions
표준 변수 교체
Replaces with the string representation of the parameter, or the model itself if a parameter is not specified. If the substitution can not be performed, for instance if you specify an invalid model property, it will be substituted with
[Err!]
Syntax
@Model[.Parameters]
Example
Hello @Model.Name, your age is @Model.User.Age
I 교체 기
Enables you to iterate over models that are collection. Iterators cannot be nested
Syntax
@Each[.Parameters]
[@Current[.Parameters]]
@EndEach
@Each
will implicitly be associated with the model and for each iteration the @Current
will represent the current item in the collection. @Current
can be used multiple times in the iterator block, and is accessed in the same way as @Model
. Example
@Each.Users
Hello @Current.Name!
@EndEach
조건.
Parameters must be a boolean (see Implicit Conditionals below). Nesting of @If and @IfNot statements is not supported.
Syntax:
@If[Not].Parameters
[contents]
@EndIf
Example
@IfNot.HasUsers
No users found!
@EndIf
내포 식 조건
If the model has property that implements
ICollection
then you can use an implicit conditional. The implicit conditional syntax is the same as a normal conditional, but the Parameters
part can have a Has
-prefix. The conditional will be true if the collection contains items, and false if it does not or if it is null. Syntax
Has[CollectionPropertyName]
Example
@If.HasUsers
Users found!
@EndIf
The above example will expand to "Users found!" if the model has a collection called
Users
and it contains items; if the collection is empty then the text would not be displayed. HTML 인 코딩
Both the
@Model
and @Current keywords
(with or without parameters) can have an optional !
operator, after the @
, to HTML encode the output. Syntax
@!Model[.Parameter]
@!Current[.Parameter]
Example
@!Model.Test
@Each
@!Current.Test
@EndEach
부분 페이지
Renders a partial view. A property of the current model can be specified to be used as the partial view's model, or it may be omitted to use the current view's model instead. The file extension of the view is optional.
Syntax
@Partial['<view name>'[, Model.Property]]
Example
// Renders the partial view with the same model as the parent
@Partial['subview.sshtml'];
// Renders the partial view using the User as the model
@Partial['subview.sshtml', Model.User];
홈 페이지 와 세 션
You can put shared layout in a master page and declare content sections that will be populated by the views. It is possible to have nested master pages and you are not obligated to provide content for all of the content sections.
The master pages will have access to the
@Model
of the view and the file extension is optional when specifying the name of the master to use in your view. You can use the
@Section
tag multiple times and is used to both declare a content section, in a master page, and to define the content blocks of a view. Syntax
@Master['<name>']
@Section['<name>']
@EndSection
Example
// master.sshtml
<html>
<body>
@Section['Content'];
</body>
</html>
// index.sshtml
@Master['master.sshtml']
@Section['Content']
This is content on the index page
@EndSection
위조 방지 영패
Renders an anti-forgery token, on the page, in an hidden input to prevent cross-site request forgery attacks. The token will automatically be validated when a new request is posted to the server (assuming CSRF protection hasn’t been turned off).
Syntax
@AntiForgeryToken
Example
@AntiForgeryToken
경로 확장
Expands a relative paths to a fully qualified URL.
Syntax
@Path['<relative-path>']
Example
@Path['~/relative/url/image.png']
Starting from v1.2, SSVE performs automatic path expansion in all HTML attributes (more specifically, in all
name="value"
pairs, both with single and double quotes around value
) where attribute value starts with ~/
. For example, <a href="@Path['~/relative/path']" ...>
can be significantly shortened to <a href="~/relative/path" ...>
. 확장 SSVE
It is possible to extend the SSVE to support additional 'matchers' to meet your needs.This stackoverflow post gives an example of how to do this by describing how you could extend the SSVE to support text translation substitutions similar to the "@Text.TranslationKey" token support of the Razor View Engine.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
MVC에 대해 대략 정리해 보았습니다.애플리케이션 개발에 효과적인 디자인 패턴 Model View Controller(MVC)에 대해 정리해 본다. 효율적으로 개발하는 디자인 패턴이다. 다음 그림은 MVC를 나타내는 개략도입니다. MVC는 Model, ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.