We are proud to announce about our new open source project – Knockout MVC. It is a library for ASP.NET MVC3 , that is a wrapper for Knockout.js, that helps to move entire business logic to the server side: the complete JavaScript code necessary on the client side will be generated automatically based on the described C# (or VB.NET) model. |
You may ask: so what is so special about it? Let us show it to you on a real example!
Task:
So, let’s imagine a task: we want to provide user with the ability to edit some data model. And some data handler logic is hosted on the server (for example, saving to database). So, we want to use ajax to send requests to server in order to avoid page re-load. But using ajax results in the necessity to describe logic on the client side that will be able to update the page based on the response. Besides, it is necessary to describe some part of data model processing on the client side using JavaScript in order to arrange good dynamic user interface.
Standard ASP.NET ways:
Let’s see how to solve this without using any library under ASP.NET:
- [JavaScript] Describe data model on the client side
- [JavaScript] Describe logic of initialization of edit fields
- [JavaScript] Describe logic of data model processing on the client side
- [JavaScript] Describe logic of data transmission to server (manually collect data from the necessary fields and serialize it)
- [C#] Describe data model on the server side
- [C#] Describe logic of de-serialization of the client query to the model
- [C#] Describe logic of data model processing on the server
- [C#] Describe logic of serialization of the model and sending new data back to the client
- [JavaScript] Describe logic of de-serialization of the response to the existing model
- [JavaScript] Describe logic of updating user interface elements according to new data
If the model quite small, these actions are quite obvious, but if you want to add new property or method to the model you will need to carefully write considerable amount of code.
Using Knockout MVC:
Don’t be so sad in advance — now you have a new wonderful library! Let’s see what will be solution of our task with the use of Knockout MVC.
- [C#] Describe data model and logic of its processing on the server
- [C#] Specify what data model element corresponds to every interface element
That’s all! The rest of logic will be generated automatically!
Refactoring of such Web application won’t differ from refactoring of common C# application. You don’t need to remember name of any property or method – IntelliSence will help you write its name correctly. And even if there is an error, you will know it on the compilation stage. If some simple logic should be executed on both client side and server side (for example, validation of form fields), it is written in C# just once (then this code will be converted to JavaScript).
Got interested?
Visit us at http://knockoutmvc.com to get deeper into understanding how Knockout MVC can help you spend up your development and improve its quality!