2 Replies - 345 Views - Last Post: 15 February 2019 - 03:02 AM Rate Topic: -----

#1 ahmedba   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 24-January 14

Are project MVC must be web api to connect to angular ?

Posted 14 February 2019 - 06:42 PM

Problem

I work on asp.net core 2.1 project with sql server 2014

This project is mvc controller not web api .

We decide to make client side with angular 7 so that i will have two project

Project have angular client side

Another project is asp.net core mvc or web api server side .

So that my question

Are my project mvc controller must be web api to connect to angular ?

This post has been edited by ahmedba: 14 February 2019 - 06:43 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Are project MVC must be web api to connect to angular ?

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6798
  • View blog
  • Posts: 28,102
  • Joined: 12-December 12

Re: Are project MVC must be web api to connect to angular ?

Posted 15 February 2019 - 02:50 AM

Angular is intended for a Single Page Application (SPA). In this context it makes sense that it would connect to a Web API to obtain and modify data, via a service layer.

In ASP.NET Core the distinction between MVC and Web API is blurred. (I believe they both share a common ControllerBase.) In simple terms I think the distinction is that Web API does not use Razor or return a View, but returns, or acts upon, data inline with Http Verbs (GET, POST, PUT, DELETE).

You could start with either project type and easily switch between them. (Or even from an empty .NET Core project.)

Your new Angular application could communicate with your existing MVC if needed.

It is possible for a project to include both Angular as an SPA and ASP.NET Core MVC routed views, or for them to work together as two separate projects. For example, the main page might operate as an SPA, but with links to other areas within the site that have a more traditional paged (MVC Views) navigation. The only caveat with this approach is that you then have two different models (Angular and Core MVC) to handle routing. It is not such a concern, though, as the Angular routing is isolated to a single page (or pages).

(You'd probably also need to expend some energy keeping the site-design between them consistent.)
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6798
  • View blog
  • Posts: 28,102
  • Joined: 12-December 12

Re: Are project MVC must be web api to connect to angular ?

Posted 15 February 2019 - 03:02 AM

[My recent project I was asked to use Angular, for a "better user experience". What nonsense. It is a fairly simple site, with nothing particularly sexy going on within a page. It tripled the development time.]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1