Is there a possibility to write a C# variable into ko.observable() variable? For instance, i have two radio buttons(true and false) with "data-bind="checked: isEvent". I need to initialize this ko.observable - "isEvent" value, with @Model.isEvent right before rendering those two radiobuttons, to get proper radiobutton checked.
Alternatively, you can serialize your model into a single variable in the head of your document, and then access properties that way, so that you don't have to include your entire view model in your view.
Based on your comments, here is a more complete example of how this would work.
In your layout page:
@using Newtonsoft.Json
<!-- this should already be referenced in your project, but if not use Nuget to install it -->
<!DOCTYPE html>
<head>
<title>Title</title>
<script type="text/javascript">
var model = @Html.Raw(JsonConvert.SerializeObject(Model));
//Alternatively, you can omit any serialization, and just use:
var isEvent = @Model.isEvent;
</script>
<script src="path_to_view_model.js"></script>
</head>
In your KO view model:
function ViewModel() {
var self = this;
self.isEvent = ko.observable(model.isEvent);
}