28

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=... /> 
johndoe
  • 291
  • 1
  • 4
  • 5
  • How do you conclude "does not work", what is happening. From the code you post, I cannot see if this is from your View or controller. Post just a little more (wrapping {} or would be nice to get the context). – GvS Jan 21 '11 at 14:23
  • 1
    @johndoe, the answer sorts the issue out. could you mark it as answer? – AnarchistGeek Feb 05 '12 at 20:01
  • http://stackoverflow.com/questions/6671086/is-there-a-way-to-concatenate-strings-in-html-attributes – AnarchistGeek Feb 05 '12 at 20:04

3 Answers3

48

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)

Omu
  • 69,856
  • 92
  • 277
  • 407
33

Correct Syntax

id="@("chk_"+@item.Id)"
Milen
  • 8,697
  • 7
  • 43
  • 57
Saboor Awan
  • 1,567
  • 4
  • 24
  • 37
0

This does works now in latest MVC:

id="chk_@item.OrderNumber"

Happy coding.

anil shrestha
  • 2,136
  • 2
  • 12
  • 26