Book Image

Getting Started with Knockout.js for .NET Developers

By : Andrey Ankshin
Book Image

Getting Started with Knockout.js for .NET Developers

By: Andrey Ankshin

Overview of this book

Table of Contents (14 chapters)
Getting Started with Knockout.js for .NET Developers
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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)