Can someone explain to me why would I use Knockout.js with ASP.NET MVC? Doing some research it looks like the major usage of knockout.js is for the data-bindings. But why would I need to use knockout.js when I can bind elements with strongly-typed Views and using Razor?
Instead of the Knockout way:
<td data-bind="text: Id"></td>
Can't I just do this with Razor?
<td>@Model.Id</td>
I see that knockout is now included in MVC 4 but not sure how I can utilize it.
Sorry if this has been asked before but I did some searches on SO but I couldn't find anything that was clear to me.
Basically MVVM js frameworks such as knockoutjs are intended to be used in Single Page Applications where you have a minimum of server side logic, a single server handler or MVC controller action if you wish, that is serving some HTML. And all the application logic is written in javascript. There are only AJAX calls to REST services from the client and all the view models live on the client. The server will only send an initial JSON model to the client but all the interaction with this model will happen on the client.
So while you can achieve lots of the logic in Razor, this stays server side processing. If you want a very dynamic application which is implemented entirely on the client side you might consider using such framework on the client.
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