I'm currently evaluating the programming model for creating future Webapplications in my company. So I will decide between ASP.NET MVC 5 (with Razor Views) and AngularJS with ASP.NET WebAPI. What are the advantages / disadvantages of these two programming models?
-
5Well... if you're going to anchor AngularJS to ASP.NET... you're not really giving it a fair comparison. It's like you're looking to take the Javascript out of Angular, and that's just not the way it's meant to happen. Angular is meant to be your framework for the client, and works best when you use very little server side templating: simple-talk.com/blogs/2013/10/16/…. Things like authentication and such make sense, but leave razor out, and just go straight .NET and create an API layer for Angular with it.Brian Vanderbusch– Brian Vanderbusch2014-04-15 07:15:21 +00:00Commented Apr 15, 2014 at 7:15
-
4I think what you really need is just AngularJS with ASP.NET WebAPI. I think it has best of both world. I tried mixing MVC with AngularJS and it was not very nice experience when I ran into issues, so would suggest not to get in to that trap. One thing I miss with this approach is the device based views that MVC with Razor engine can provide. There must be a way to overcome this, but I didn't expriment enough yet.Kiran– Kiran2014-05-07 03:39:37 +00:00Commented May 7, 2014 at 3:39
-
1Having worked with Angular for just a few short months (although it seems like forever), I would never go back to Razor. The more you work with Angular, the more you come to appreciate it - flexibility and power, sometimes it feels like magic. I should say that Web API does not play nicely with Angular, at least on the form POST, but that could be worked out. It is not an easy transition for a C# programmer syntax wise, as javascript is not a strongly typed language. But as you overcome this hurdle, you would come to appreciate Angular.Florida G.– Florida G.2015-11-09 00:14:21 +00:00Commented Nov 9, 2015 at 0:14
-
1Razor is a horrible thing even among templating engines. You'll notice a drastic increase in productivity when using angular over any templating engine (Jade, handlebar, razor etc). Use a backend which serves JSONs (can be web-api, node-express or PHP) and a angular front end. And just to note, knockout is not nearly as good as angular.... All the best...Giridhar Karnik– Giridhar Karnik2016-01-30 19:59:51 +00:00Commented Jan 30, 2016 at 19:59
-
2@BrianVanderbusch Not really sure what you're talking about. The backend doesn't matter at all. It could be anything. He's saying he'll use ASP.NET as the backend and angular as the client side front end. Angular still needs to make calls to the server for data. This has nothing to do with not giving Angular a fair comparison.user441521– user4415212016-10-14 14:24:37 +00:00Commented Oct 14, 2016 at 14:24
2 Answers
My 2 cents. I personally prefer pure HTML views, an entirely angular front end along with a Web API/EF/SQL Server back end, basically no Razor. Razor is an abstraction to help programmers render HTML, these days everyone's coming to the conclusion that removing these abstractions is a better idea, hence the evolution of ASP.NET from web forms, to MVC etc. It's not really difficult for developers to get to grips with HTML and use an angular front end, moreover this makes UI designers jobs easier, they have pure HTML and JSON/Javascript, they don't need to go about understanding MVC, Razor, controllers and actions. We used to work completely on MVC, in our latest project we moved to a Web API back end and an angular front end, and we've noticed that our UI designer's productivity has vastly improved.
7 Comments
I believe you cannot compare. AngularJS is a Single Page Application (SPA) framework whereas ASP.Net MVC use the standard model where one navigates between pages. Whether you want to build a SPA is decided by factors like
- Do you want SEO. Which most of these JS rich framework have limited support.
- How can you structure your app as SPA or multiple SPAs.
- Coming from a type safe language C# to JavaScript programming is a challenge.
- Learning AngularJS and using it effectively.
We use the standard MVC 5 razor view to setup the initial AngularJS views so you can even combine them together if required.
See this answer Can you use AngularJS with Parse.com? to derive more context.