How to concatenate the id of the HTML element usin

2019-02-04 09:27发布

问题:

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 chk_@item.CustomerId.

// using the telerik grid 
id="chk_@item.OrderNumber"  // 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="chk_@item.Customernumber" name="@item.CustomerNumber" value="@item.OrderNumber" /></text>).Width(50)

the above will render as

<input type="checkbox" id="chk_@item.Customernumber" value=... /> 

回答1:

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



回答2:

Correct Syntax

id="@("chk_"+@item.Id)"