티스토리 뷰
C# Razor Syntax Quick Reference
C# Razor 문법 기존 웹폼 레퍼런스와의 차이점. 출처 : http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx
- 발음 : 레이저 (Razor)
- @으로 표현
- ASP.NET 엔진과 별개로 동작
- Razor Template + Data = Output
Syntax/Sample | Razor | Web Forms Equivalent (or remarks) |
---|---|---|
Code Block | @{ int x = 123; string y = "because."; } | <% int x = 123; string y = "because."; %> |
Expression (Html Encoded) | <span>@model.Message</span> | <span><%: model.Message %></span> |
Expression (Unencoded) | <span> @Html.Raw(model.Message) </span> | <span><%= model.Message %></span> |
Combining Text and markup | @foreach(var item in items) { <span>@item.Prop</span> } | <% foreach(var item in items) { %> <span><%: item.Prop %></span> <% } %> |
Mixing code and Plain text | @if (foo) { <text>Plain Text</text> } | <% if (foo) { %> Plain Text <% } %> |
Mixing code and plain text (alternate) | @if (foo) { @:Plain Text is @bar } | Same as above |
Email Addresses | Hi philha@example.com | Razor recognizes basic email format and is smart enough not to treat the @ as a code delimiter |
Explicit Expression | <span>ISBN@(isbnNumber)</span> | In this case, we need to be explicit about the expression by using parentheses. |
Escaping the @ sign | <span>In Razor, you use the @@foo to display the value of foo</span> | @@ renders a single @ in the response. |
Server side Comment | @* This is a server side multiline comment *@ | <%-- This is a server side multiline comment --%> |
Calling generic method | @(MyClass.MyMethod<AType>()) | Use parentheses to be explicit about what the expression is. |
Creating a Razor Delegate | @{ Func<dynamic, object> b = @<strong>@item</strong>; } @b("Bold this") | Generates a Func<T, HelperResult> that you can call from within Razor. See this blog post for more details. |
Mixing expressions and text | Hello @title. @name. | Hello <%: title %>. <%: name %>. |
NEW IN RAZOR v2.0/ASP.NET MVC 4 | ||
Conditional attributes | <div class="@className"></div> | When
<div></div>When className = "" <div class=""></div>When className = "my-class" <div class="my-class"></div> |
Conditional attributes with other literal values | <div class="@className foo bar"> </div> | When
<div class="foo bar"></div>Notice the leading space in front of foo is removed. When className = "my-class" <div class="my-class foo bar"> </div> |
Conditional data-* attributes. data-* attributes are always rendered. | <div data-x="@xpos"></div> | When
<div data-x=""></div>When xpos = "42" <div data-x="42"></div> |
Boolean attributes | <input type="checkbox" checked="@isChecked" /> | When isChecked = true <input type="checkbox" checked="checked" /> When isChecked = false <input type="checkbox" /> |
URL Resolution with tilde | <script src="~/myscript.js"> | When the app is at / <script src="/myscript.js">When running in a virtual application named MyApp <script src="/MyApp/myscript.js"> |
'프로그래밍 > ASP.NET' 카테고리의 다른 글
Page.GetPostBackEventReference 자바스크립트에서 ASP.NET 함수실행 (0) | 2013.03.26 |
---|---|
ASP.NET 인라인태그(inline tag) <%, <%=, <%# 등등 (0) | 2013.02.28 |
ASP.NET에서 Trace를 이용한 웹페이지 속도 및 성능 측정 (0) | 2012.12.28 |
별도의 메일서버 없이 gmail 을 이용해서 메일 보내기 (0) | 2012.12.26 |
C# 으로 만든 DLL asp에서 사용 (암호화, 복호화) (0) | 2012.11.15 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- Ajax
- JavaScript
- drag&drop
- 프로시저
- Excel
- jQuery Mobile
- 제이쿼리
- 저장프로시저
- ASP.NET
- Style
- json
- JS
- WebApi
- IE
- MSSQL
- Mobile
- WCF
- Chart
- css3
- jquery chart
- rowspan
- radius
- 자바스크립트
- 셀렉터
- grid
- jQuery
- SVG
- workbook
- html5
- CSS
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
글 보관함