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 f
Just put your variable next to prefix:
<input type="checkbox" id="chk@(obj.field)" />
Best way to concate any C# variable in rozer view by using string.Format
id="@string.Format("{0}_Title", _Id)" // Apend after
id="@string.Format("Title_{0}", _Id)" // Apend before
id="@string.Format("Title_{0}_Title", _Id)" // Apend Middle
<input type="checkbox" id="chk@(obj.field)" />
should work.
<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")
Try
<input type="checkbox" id="@("chk" + obj.field)" />
or
<input type="checkbox" id="chk@obj.field" />