开发者

Can you use @ instead of <% in ASP.net

I am seeing some examples online where the @ is being used before server side code.

eg

<h2&g开发者_运维问答t;Browsing Genre: @Model.Name</h2>

So can you just use a single @ instead of wrapping the c#/vb code in <% %> ?


You can use @ if you're using the Razor view engine in ASP.NET MVC. That's most-likely what you're seeing examples of.


This is indeed razor syntax from MVC 3. Here is the syntax comparisons side by side http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx

Note @ html encodes everything by default unless whatever after the @ returns an MvcHtmlString. <% %> in web forms did not html encode, but <%: %> syntax does.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜