i'm trying to concatenate a string in asp.net mvc 3 razor and i'm getting a little sintax problem with my cshtml.
i what to generate an id for my checkboxes on a foreach statement, and my checkboxes should start with "chk" and what to cancatenate a fieldon the ID, something like that:
<input type="checkbox" id="[email protected]" />
but or exampple the result for id attribute is: id="chk+8"
how can i just get a result for something like "chk8"?
Just put your variable next to prefix:
<input type="checkbox" id="chk@(obj.field)" />
Try
<input type="checkbox" id="@("chk" + obj.field)" />
or
<input type="checkbox" id="[email protected]" />
<input type="checkbox" id="chk@(obj.field)" />
should work.
The most direct and clean way to add a prefix a suffix.
@("PREFIX " + obj.field + " SUFFIX")
<input type="checkbox" id="chk@(obj.field)" />
should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With