Mayank
Mayank

Reputation: 968

Mixing code with markup in Razor

Can we do something like

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

in Razor to produce

I tried

<tr id="[email protected]">

which did not work. It rendered <tr id="[email protected]"> I am looking for -

<tr id="prod1234">

Upvotes: 2

Views: 649

Answers (1)

Buildstarted
Buildstarted

Reputation: 26689

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 [email protected] 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.

Upvotes: 7

Related Questions