Knockout. js helps you build the UI in Model-View-viewmodel (mvvm) mode.
This article provides the implementation of scriptsharp based on the example provided by http://learn.knockoutjs.com.
For more information about scriptsharp Quick Start, see: http://www.cnblogs.com/laojia/archive/2011/09/29/2195611.html.
In this example, the scriptsharp Project template is jquery library. After the project is created, you must manually Add a reference to script. Knockout. dll located in the scriptsharp installation folder.
Directly paste the Code:
Page. CS
using System;using System.Runtime.CompilerServices;using jQueryApi;using KnockoutApi;using ScriptSharpKnockout.KnockoutTutorial;namespace ScriptSharpKnockout{ [GlobalMethods] internal static class Page { static Page() { jQuery.OnDocumentReady(delegate { Knockout.ApplyBindings(new ViewModel()); }); } }}
Viewmodel. CS
Using knockoutapi; namespace scriptsharpknockout. knockouttutorial {public class viewmodel {public observable <string> firstname = knockout. observable <string> ("first name"); Public observable <string> lastname = knockout. observable <string> ("last name"); Public dependentobservable <string> fullname; Public viewmodel () {fullname = knockout. dependentobservable <string> (delegate {return "Hello:" + firstname. getvalue () + "" + lastname. getvalue () ;}) ;}public void updatevalue () {This. lastname. setvalue (this. lastname. getvalue (). touppercase ());}}}
Index.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Attaches a project package for download test: http://files.cnblogs.com/laojia/ScriptSharpKnockout.zip