Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the main advantages of Knockout java script library with MVC 3

Today I was looking into Knockout JavaScript library and its features. Now I want to use this with MVC 3 applications but What is the benefits to use this with MVC 3?

like image 571
Ramesh Joshi Avatar asked Feb 23 '12 11:02

Ramesh Joshi


3 Answers

Knockout is an MVVM pattern that works with a javascript ViewModel. The reason this works well with MVC is that serialization to and from javascript models in JSON is very simple.

Also, it will be included in MVC4. Here is a video by the Knockout creator on how to use it for single page applications in MVC4 (with Microsoft's new Web API feature):

http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2159

But the benefits are really that MVVM allows you to develop rich UI's with a lot less coding (if you are familiar with Silverlight or WPF MVVM you'll know just what I mean).

Given a ViewModel of:

var myViewModel = { myValue: 'some text' };

You do not need to bind

$('#textBox').change(function() { myViewModel.myValue = $(this).val(); })

and the reverse of

$('#textBox').val(myViewModel.myValue)

all over the place, or special code handling of computed properties in your view in Knockout. You can do it all in a very nice object oriented fashion.

<input type="text" data-bind="value: myValue" />

And all the events are wired up.

like image 158
Paul Tyng Avatar answered Nov 02 '22 18:11

Paul Tyng


The benifits are more structured, flexible client-side javascript code. You can partition better the UI and can go so far that you end up with "a-single-page-website"... which does only do json requests (If you would like to) means less server round trips smaller responds, etc...

And for me the really cool think is the binding via observables...

http://knockoutjs.com/documentation/observables.html

Also check this out: MVC + Knockoutjs = Client side MVVM bliss http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2378

like image 20
silverfighter Avatar answered Nov 02 '22 20:11

silverfighter


The benefits are listed here - http://knockoutjs.com/documentation/introduction.html

like image 28
devdigital Avatar answered Nov 02 '22 20:11

devdigital