ASP.NET MVC Razor Concatenation

How about using String.Format? like this:

<li id="@String.Format("item_{0}", item.TheItemId)">


I prefer:

<li id="@String.Concat("item_", item.TheItemId)">

The verbosity tells the support developers exactly what is happening, so it's clear and easy to understand.


You can even use this way to concat more strings:

<li id="@("item-"+item.Order + "item_"+item.ShopID)" class="ui-state-default"></li>

Here is another post.

Hope helps someone.


You should wrap the inner part of the call with ( ):

<li id="item_@(item.TheItemId)">