5

I have Html written in Razor syntax:

@for (var i = 0; i < Model.AllBetStatuses.Count; ++i)
{
    <li class="betReportingCheckbox">
        @Html.CheckBoxFor(m => m.AllBetStatuses[i].Checked, new { @class =   
         "betStatusCheckboxes"})
        @Html.DisplayFor(m => m.AllBetStatuses[i].Name)
        @Html.HiddenFor(m => m.AllBetStatuses[i].Value)
    </li>
}

I want to use knockout.js to bind these values, but when I try something of this type:

@Html.CheckBoxFor(m => m.AllBetStatuses[i].Checked, new { @class =   
         "betStatusCheckboxes", @data-bind="..."})

I get a syntax error, because the '-' character is not valid there. Is there any simple way to do this using Razor syntax?

tereško
  • 57,247
  • 24
  • 95
  • 149
Fat Shogun
  • 929
  • 1
  • 10
  • 18

1 Answers1

16

Replace the '-' by an '_'

@Html.CheckBoxFor(m => m.AllBetStatuses[i].Checked, new { @class =   
     "betStatusCheckboxes", @data_bind="..."})

I hope it helps.

Damien
  • 8,749
  • 3
  • 31
  • 38