How to concatenate the id of the HTML element using Razor ASp.NET MVC

johndoe picture johndoe · Jan 21, 2011 · Viewed 23.8k times · Source

I have a grid column with checkboxes and I want to give them a different id. Id is based on the CustomerId in the Model. What syntax should I use to concatenate the [email protected].

// using the telerik grid 
id="[email protected]"  // does not work 

// this will put the value of @item.Customernumber as the checkbox id

columns.Template(@<text><input type='checkbox' id="@item.Customernumber" name="@item.CustomerNumber" value="@item.OrderNumber" /></text>).Width(50)

second option:

columns.Template(@<text><input type='checkbox' id="[email protected]" name="@item.CustomerNumber" value="@item.OrderNumber" /></text>).Width(50)

the above will render as

<input type="checkbox" id="[email protected]" value=... /> 

Answer

Omu picture Omu · Jan 21, 2011

[email protected] will not work because razor thinks of it as of an e-mail, you need to do it like this instead: chk_@(item.OrderNumber)