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?
Knockout's declarative binding system provides a concise and powerful way to link data to the UI. It's generally easy and obvious to bind to simple data properties or to use a single binding.
In a data binding process, each data change is reflected automatically by the elements that are bound to the data. The term data binding is also used in cases where an outer representation of data in an element changes, and the underlying data is automatically updated to reflect this change.
Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML.
Replace the '-' by an '_'
@Html.CheckBoxFor(m => m.AllBetStatuses[i].Checked, new { @class =
"betStatusCheckboxes", @data_bind="..."})
I hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With