4

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.

1
  • One of the benefits of this would be putting less load on the server and more on the client. You can let the local client handle all the databindings or let the server. Commented Feb 15, 2014 at 22:22

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Not necessarily a SPA.Routes may still remain on the server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.