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?

3
  • did you try ...,"data-bind" = "..."... ? (or ...,data-bind = "..."...) Commented Oct 2, 2013 at 11:15
  • iirc, it should just be: data_bind="..." Commented Oct 2, 2013 at 11:18
  • possible duplicate of How to use HTML-5 data-* attributes in ASP.NET MVC Commented Oct 2, 2013 at 11:30

1 Answer 1

16

Replace the '-' by an '_'

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

I hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

I figured it out later, but when I returned here you already had the answer so I'll mark your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.