ASP.Net MVC vs. HTML + KnockoutJS + WebAPI

architecture, asp.net-mvc-4, jquery, knockout.js

Solution

Great question. I'm certainly finding that my MVC / Razor code is becoming less and less as I progress with my Knockout project, but I think I'll always have some aspects of the views which I want to be determined server-side.

Fundamental contextual stuff like whether to render a logged in / logged out panel in a layout page, role related decisions as to what should be accessible, etc. I guess if you were careful enough with your security and implement sufficient guard code on the server when someone actually tries to do something then you could achieve most of that in Knockout, but you'd probably end up with a huge amount of bloat, catering for every possible part of the view.

It probably depends on your application but I think for most web apps there's a fairly common sense division between what should be determined at server render time and what should be done on the client.

If nothing else, you may want links etc in your views to be indexed by search engines. If you pass down, say, your "latest 10 products" in JSON and render them with hyperlinks in a Knockout template, you'd lose out on that.

Problem

I'm wondering why not just have static HTML files in an ASP.Net MVC 4 Web Project that use jQuery+jQuery Templates+KnockoutJS combination consuming REST based (ASP.Net MVC 4 WEB API hosted on Azure & secured using ACS). The Web API can use Entity Framework and return JSON serialized objects that can be retrieved using $.ajax() and bound using KnockoutJS. What is it that ASP.Net MVC (for the Web pages) provides that adds value to this architecture? On top of my head, I can think of: - Multi device support (device detection and template replacement) - Server-side validations of submitted data (not sure as I can also put the validations on WEB API?) - I can still rewrite my URLs even if I'm using static html files (since I'm using ASP.Net MVC anyway). Can someone help me understand this better? Thanks in advance.

Original source