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

3

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 [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=... /> 
Manducate answered 21/1, 2011 at 14:20 Comment(3)
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 <tag> would be nice to get the context).Style
@johndoe, the answer sorts the issue out. could you mark it as answer?Leatherjacket
#6671586Leatherjacket
D
48

[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)

Denisdenise answered 21/1, 2011 at 14:40 Comment(2)
it appends '(' as well in dataPierides
Here is another post, hope helps someone.Seldon
P
34

Correct Syntax

id="@("chk_"[email protected])"
Pierides answered 4/5, 2012 at 5:29 Comment(0)
C
0

This does works now in latest MVC:

id="[email protected]"

Happy coding.

Clotilde answered 2/6, 2020 at 8:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.