How to concatenate the id of the HTML element usin

2019-02-04 09:05发布

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=... /> 

2条回答
beautiful°
2楼-- · 2019-02-04 09:15

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)

查看更多
太酷不给撩
3楼-- · 2019-02-04 09:34

Correct Syntax

id="@("chk_"+@item.Id)"
查看更多
登录 后发表回答