2

I want to build responsive SPA web application. I followed old paradigms before and the way it is supposed to be done nowadays is not very familiar to me, so sorry if my question seems unadequate.

Now I'm trying to understand the motivation behind this MVC 5 SPA template: why would I need to use MVC and Web API in one application?

My app will not act as a service. I can simply return JSON from my action methods. If in my case it is absolutely not neccessary, what factors could change the situation in favor of using both WebAPI and MVC at the same time?

adiga
  • 34,372
  • 9
  • 61
  • 83
Orif Khodjaev
  • 1,080
  • 1
  • 13
  • 34
  • 1
    I think Shaun Wilson's answer in this question will also answer yours: http://stackoverflow.com/questions/10346342/when-to-use-webapi-vs-controller-in-asp-net-mvc – Mathew Thompson Feb 20 '15 at 12:44

1 Answers1

2

You don't have to but it is useful.

I'm usually using MVC for

  • generating initial html file for my SPA through index.cshtml (bundles + some customization of initial html code)
  • generating dynamic JavaScript code (usually for something like configuration angular modules)

Web API or OData kicks in aferwards providing endpoints for your favourite SPA framework (angular / knockout etc.) returning json or even xml if you need.

milanio
  • 4,082
  • 24
  • 34