O'Reilly logo

Getting Started with Knockout.js for .NET Developers by Andrey Akinshin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding user-defined scripts

If necessary, you can add your own Knockout.js code to the automatically generated code. It is important to initialize the generated model with the following code:

@ko.Initialize(Model)

This method will create a model named viewModel and fill it with data that is taken from the Model parameter. Then, you can add custom JavaScript code and extend a model:

<script type="text/javascript">
  viewModel.someProperty = someValue;  
</script>

After the necessary custom script is added, you should activate Knockout with the following code:

@ko.Apply(Model)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required