开发者

Mixing code with markup in Razor

Can we do something like

<tr id="prod<%:item.ProductId%>">

in Razor to produce

I tried

开发者_开发百科
<tr id="prod@item.ProductId">

which did not work. It rendered <tr id="prod@item.ProductId"> I am looking for -

<tr id="prod1234">


You'll have to use the @() around your particular model value like so:

<div id="prod@(item.ProductId)"></div>

The reason for this is because the prod@item.ProductId looks like an email address to the parser and by default the parser tries to ignore email addresses so you don't have to do something silly like john@@doe.com as emails are common enough that it would be annoying to do every time. So the people working on the razor parser just figured: "if it looks like an email, ignore it". So that's why you're having this particular issue.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜