Backbone.js – Using with ASP.Net MVC

asp.net-mvcjavascript

I'm currently looking into the advantages of using Backbone.js, but I'll be using ASP.Net MVC as the main bulk of the site. My question is, is it worth blending the 2 together or am I making a rod for my own back? Should I just use an ASP.Net Web Forms site instead?

Best Answer

Should I just use an ASP.Net Web Forms site instead?

Not unless you have strict deadlines or other limitations. It's always worthwhile investing time and resources in better technologies like ASP.NET MVC.

As for using backbone.js it will work with any REST API. You can expose a REST API with ASP.NET MVC (and it's a lot easier to do then using ASP.NET winforms)

As long as you expose your data as a service backbone can work with it nicely. Alternatively you can use ASP.NET MVC on it's own and not make use of the client-side MVC backbone offers.

is it worth blending the 2 together or am I making a rod for my own back?

As mentioned if you just use ASP.NET MVC to expose data as an REST API then this is fine. If you use ASP.NET MVC to serve an entire website (including server-side views) then you'll have a lot of code duplication.

However with modern ajax and JavaScript driven websites you will have this code duplication anyway. You might as well use backbone or not use any client-side JavaScript / ajax code.

If your writing a heavy client based website with lots of interactive JavaScript based ui you might aswell use these libraries to structure and organise your code

However if your using backbone.js I would recommend you couple it with node.js to minimize code duplication or couchapp to remove the server-side stack. You don't really need .NET if your using backbone.