Knockout data binding attribute in razor syntax

I have an Html written by 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 like this:

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

I get a syntax error because the '-' character is invalid there. Is there an easy way to do this using Razor syntax?

+4
source share
1 answer

Change to '_'

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

Hope this helps.

+14
source

All Articles