日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

Asp.net MVC razor语法参考

發(fā)布時間:2023/12/9 c/c++ 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Asp.net MVC razor语法参考 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Razor語法的快捷參考http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/

只是copy下來便于查閱!

?

I gave a presentation to another team at Microsoft yesterday on ASP.NET MVC and the Razor view engine and someone asked if there was a reference for the Razor syntax.

It turns out, there is a pretty?good guide about Razor?available, but it’s focused on covering the basics of web programming using Razor and inline pages and not just the Razor syntax.

So I thought it might be handy to write up a a really concise quick reference about the Razor syntax.

Syntax/SampleRazorWeb 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 <% } %>
Using block @ using (Html.BeginForm()) {<input type="text" value="input here"> } <% using (Html.BeginForm()) { %><input type="text" value="input here"> <% } %>
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?className = null <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?className = null <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?xpos = null or "" <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">
</script>
When the app is at?/ <script src="/myscript.js">
</script>
When running in a virtual application named?MyApp <script src="/MyApp/myscript.js">
</script>

Notice in the “mixing expressions and text” example that Razor is smart enough to know that the ending period is a literal text punctuation and not meant to indicate that it’s trying to call a method or property of the expression.

Let me know if there are other examples you think should be placed in this guide. I hope you find this helpful.

UPDATE 12/30/2012:I’ve added a few new examples to the table of new additions to Razor v2/ASP.NET MVC 4 syntax. Razor got a lot better in that release!

Also, if you want to know more, consider buying the?Progamming ASP.NET MVC 4?book. Full disclosure, I'm one of the authors, but the other three authors are way better.

轉(zhuǎn)載于:https://www.cnblogs.com/dereklovecc/p/3539940.html

總結(jié)

以上是生活随笔為你收集整理的Asp.net MVC razor语法参考的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。