Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I come from using ASP.NET MVC/Web API and now I am starting to use Angular but I am not clear on the proper way to mix them.

Once I am using Angular does the MVC sever side concepts still provide any value ? Or should I strictly be using Web API purely to get data for the angular HTTP calls ?

Any tips you have for a ASP.NET MVC guy transitioning to Angular would be helpful

share|improve this question
3  
It would depend, but I would think "should I strictly be using Web API purely to get data for the angular HTTP calls" is correct way to do it. –  MikeSmithDev Jan 13 at 17:42
add comment

3 Answers

Pure Web API

I used to be pretty hardcore with ASP.NET MVC but since I've met Angular I do not see one reason why I would use any server side content generation framework. Pure Angular/REST(WebApi) gives a richer and smoother result. It's much faster and allows you to build websites that come quite close to desktop applications, without any funky hacks.

Angular does have a little learning curve, but once your team has mastered it, you'll build much better websites in less time. Mainly this has to do with the fact that you don't have all these state(less) issues anymore.

For example imagine a wizard form with any traditional server side framework. Each page needs to be validated and submitted separately. Maybe the content of the page is dependent on values from a previous page. Maybe the user pressed the back button and is re-submitting an previous form. Where do we store the state of the client? All these complications do not exist when using Angular and REST.

So ... come over to the dark side ... we've got cookies.

Similar question

share|improve this answer
1  
+1 for cookies. –  calebboyd Jan 13 at 18:14
 
I agree re: the speed and smoothness of developing apps via Angular. In MVC or WebForms (ugh) you spend this time getting it to spit out markup, and then have to do a couple of passes bolting client code onto it, which feels weird, is labor intensive, and because of the disconnected nature, wastes a lot of time doing simple things. –  HackedByChinese Jan 13 at 18:15
 
Thanks, I also was wondering why we need both and came here. I see in the following post that not using MVC "makes your site invisible to search engines". stackoverflow.com/questions/19609148/… What's the deal with that? –  Narayana Jan 30 at 15:58
1  
@Narayana; This provides some SEO love. –  null Jan 30 at 19:39
add comment

AngularJS is more associated with the single page application paradigm, and as such, doesn't benefit much from server-side technologies that render markup. There is no technical reason that precludes you using them together, but in a practical sense, why would you?

An SPA retrieves the assets it needs (JS, CSS, and HTML views) and runs on its own, communicating back to services to send or retrieve data. So, a server-side technology is still necessary for providing those services (as well as other means such as authentication and the likes), but the rendering parts are largely irrelevant and not particularly useful because it's a duplication of efforts, except MVC does it on the server side and Angular does it on the client. If you're using Angular, you want it on the client for best results. You can make Angular post HTML forms and retrieve partial views from MVC actions, but you'd be missing out on the best and easiest features of Angular and making your life harder.

MVC is pretty flexible and you could use it to service calls from an SPA application. However, WebAPI is more finely tuned and a bit easier to use for such services.

I've written a number of AngularJS applications, including a couple that migrated from pre-existing WebForms and MVC applications, and the ASP.NET aspect evolves towards a platform for delivering the AngularJS app as the actual client, and for hosting the application layer the client communicates to via REST (using WebAPI). MVC is a fine framework, but it usually finds itself without a job in these sorts of applications.

The ASP.NET application becomes another layer to the infrastructure, where its responsibilities are limited to:

  • Host the dependency container.
  • Wire the business logic implementations into the container.
  • Set up asset bundles for JS and CSS.
  • Host WebAPI services.
  • Enforce security, perform logging and diagnostics.
  • Interfacing with application caches for performance.

Another great thing about an SPA is it can increase bandwidth of your team. One group can blast out the services while the other lays in the client app. Since you can easily stub or mock REST services, you could have a fully working client app on mock services and swap out for the real ones when they're done.

You do have to invest up front on Angular, but it pays off big. Since you are already familiar with MVC, you have a leg-up on some of the core concepts.

share|improve this answer
add comment

You can check out my project on my GitHub, it's use AngularJS + ASP.NET WEB API (base RESTfull API), and they are work well together. Any question, just contact me.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.