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?
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.
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
The benefits are listed here - http://knockoutjs.com/documentation/introduction.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With