Steve
Steve

Reputation: 4463

How to manually create id value using Razor C# syntax for html textbox element?

For example, I have this textbox

 <input id="@item.Id" type="number" value="@item.TotalAmount" />

and when rendered out, it becomes

<input id="1048" type="number" value="3.60" />

How do I add a letter to the id to make the rendered out textbox to become?

<input id="T1048" type="number" value="3.60" />

I tried below but it doesn't work

<input id="[email protected]" type="number" value="@item.TotalAmount" />

Upvotes: 1

Views: 171

Answers (1)

Ishwar Gagare
Ishwar Gagare

Reputation: 753

try like this it will resolve your issue

<input id="item_@(item.Id)" type="number" value="@item.TotalAmount" />

or you can also use String.Format in it like

<input id="@String.Format("item_{0}", item.Id)">

Upvotes: 1

Related Questions