String concatenation with ASP.NET MVC3 Razor

后端 未结 5 1883
长发绾君心
长发绾君心 2021-01-08 00:43

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

相关标签:
5条回答
  • 2021-01-08 01:23

    Just put your variable next to prefix:

    <input type="checkbox" id="chk@(obj.field)" />
    
    0 讨论(0)
  • 2021-01-08 01:24

    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
    
    0 讨论(0)
  • 2021-01-08 01:37

    <input type="checkbox" id="chk@(obj.field)" /> should work.

    0 讨论(0)
  • 2021-01-08 01:41

    <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")
    
    0 讨论(0)
  • 2021-01-08 01:43

    Try

    <input type="checkbox" id="@("chk" + obj.field)" />
    

    or

    <input type="checkbox" id="chk@obj.field" />
    
    0 讨论(0)
提交回复
热议问题