We are currently prototyping a new web-based product. When we started the project we decided the technology stack would be based on Bootstrap 4, Angular 4 and ASP.Net MVC 5. As we've progressed through the project we've found that we're not really using Bootstrap as other components (such as PrimeNG) appear to be easier to use and work better with Angular. One big thing we've noticed - which is the point of this questions - is that we're not using ASP.Net MVC. We have a Web API layer and all our mvc controller methods are simply calling web api methods and passing data through. My question is this: Is there any point actually using MVC? I'm starting to think we could just have Angular talk direct to the web api layer as MVC is doing nothing for us in the middle. Does anybody have any advice as to why I shouldn't do this?
-
Also consider that if your web app is calling services directly, since it's a client side application, you don't have a secure server in the middle to sanitize any client input. You may want this asp layer just to stop savvy users from directly manipulating the requests that hit the API. It's just an additional layer that you may or may not require. – Charleh Jun 20 '17 at 08:48
-
1@Charleh surely any services API used in this way should contain enough logic itself to guard against this kind of thing? If you put that kind of thing into a separate GUI-like server layer then you somewhat preclude other front-ends (e.g. mobile) from being built without duplicating that business logic. – ADyson Jun 20 '17 at 08:50
-
Depends what you have control over, how good the target API is, whether you have a basic authentication scheme or you are using tokens etc. You probably don't want to embed any sort of sensitive connection information in a client side application so you may want an indirect layer. I've worked with some shoddy APIs before! (I did a warehouse integration and the third party API was a mess...) – Charleh Jun 20 '17 at 09:00
-
@Charleh The API in question is the [Web API](https://www.asp.net/web-api). It has all authentication/model binding/abstraction properties of ASP.NET MVC. – GSerg Jun 20 '17 at 09:22
-
1@Charleh agreed it absolutely depends on the quality of the API. But OP said it's their Web API layer so they should be able to bring it up to scratch. – ADyson Jun 20 '17 at 09:37
3 Answers
No you don't need MVC at all. You can use any server language you like - either in the form of an API (probably easier) or another GUI framework like MVC.
As you've realised, Angular is just a client-side tool and doesn't care what the back-end is - it just makes HTTP requests and receives the responses, completely agnostic of the code which was used to generate those responses.
In fact, that's one of the beauties of the web - communication between browser and server is entirely done using agreed common standards (principally the HTTP protocol, supported by things like JSON), allowing an almost limitless combination of server- and client-side frameworks to work happily together so long as they both adhere to those standards.

- 57,178
- 14
- 51
- 63
You would use MVC in the case that you want the angular application to be server rendered and then served to the client. Other use case where you can force this is when you want the base code to be together and deployable from one project and not two, in the case that you have one project for webapi and another for the angular application.
In this last case, deploying two different projects will have the advantage that your angular app will be completely agnostic of you backend, this means that you just need to change the endpoints of your services and bam! Running app, no? Well not really, the contra is that you will need to configurate all the CORS related crap to it so that you client can communicate with your backend.

- 27,293
- 11
- 59
- 73
HTML helpers is the answer to your question(it really helps). Another advantage is that it provides better coupling with model and validation. To clearly answer this one would need to understand how back-end works. You would need to understand how html-helpers connect with the backend and help bring in clarity in development. Also for testing purpose ASP.net MVC + Angular is a better option.
So this decision(to use MVC.Net) is unlikely to come from a UI developer but from an architect who has various challenges to answer. 1) conformity with front and backend(better communication/ isolated development) 2) improve code reuse 3) validation when and where (boundaries) 4) type safety 5) easiness in bringing in new developers 6) testability

- 7,295
- 4
- 71
- 112
-
Testing is a good point. We're not very hot on unit testing here so I can see why MVC would be useful for that. – user1474992 Jun 20 '17 at 09:27