Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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=... />  
like image 347
johndoe Avatar asked Jan 21 '11 14:01

johndoe


People also ask

How do you give ID in Razor syntax?

Just add the id property to the html-attributes. That will override the default id generated by the editorfor-helper-methode.

Does ASP.NET MVC use razor?

Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML. It's just that ASP.NET MVC has implemented a view engine that allows us to use Razor inside of an MVC application to produce HTML.

What is @model in razor?

The @ symbol is used in Razor initiate code, and tell the compiler where to start interpreting code, instead of just return the contents of the file as text. Using a single character for this separation, results in cleaner, compact code which is easier to read.


1 Answers

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

like image 97
Omu Avatar answered Oct 09 '22 07:10

Omu