开发者

erb <% expression -%> in aspx pages

开发者 https://www.devze.com 2023-01-08 17:53 出处:网络
Do asp.net aspx views have tags that that work similar to the Ruby erb <% -%> ? I don\'t like all these line breaks in my asp.net mvc generated html.

Do asp.net aspx views have tags that that work similar to the Ruby erb <% -%> ? I don't like all these line breaks in my asp.net mvc generated html. As for the other view engines (nhaml, spark, razor) I don't want to use them yet.

Quick example of the difference between <% %> and开发者_JAVA百科 <% -%> in erb:

1. <% %>

<% 3.times do %>
Ho!<br />
<% end %>
Merry Christmas!

gives us:

Ho!<br />

Ho!<br />

Ho!<br />

Merry Christmas!

2. <% -%>

<% 3.times do -%>
Ho!<br />
<% end -%>
Merry Christmas!

gives us:

  Ho!<br />
  Ho!<br />
  Ho!<br />
  Merry Christmas!


<% %> Exists
<% -%> Does not exists

There is small chance that Razor has it. I haven't checked it yet.


To other answerers:

Notice that small minus sign. In rails it means that blank lines will be stripped out.


Not sure why you say mimic, as this notation on classic asp and asp.net predates ruby erb.

However, it does exist, and is almost identical. See here (code blocks), expressions and binding expressions.


If i'm not misstaken you shoud be able to use <%= expression %> in asp.net to output values

0

精彩评论

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