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

Working with the Hello World example in Knockout MVC


Let's create an application based on a very simple model. It will contain only two properties: FirstName and LastName. The View will contain two TextBox elements to edit properties and a span element with a greeting text. You can find the full code of the example in the supplement code bundle of this book (HomeLibrary/HelloWorld) or look for the live example on the official site (http://knockoutmvc.com/HelloWorld).

Let's create a new ASP.NET MVC 4 project and install the kMVC packages via NuGet.

Adding the model

First of all, we should create a model. We will work with a very simple example. Let's define the following model (HelloWorld/Models/HelloWorldModel.cs):

using System.Web.Script.Serialization;
using DelegateDecompiler;
using Newtonsoft.Json;

namespace HelloWorld.Models
{
    public class HelloWorldModel
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }

        [Computed]
        [ScriptIgnore...