0

I am currently working on a new MVC4 application that will be a rich application with alot of client side interaction.

Previously for MVC application I would use controllers to simplify javascript server side interaction. Now with the advent of web api and rest services I am questioning this approach.

I would be interested in fellow developers opinions as the better practice for client/server side interaction, is it be better to go with web api rather than controller actions for such interaction?

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
amateur
  • 43,371
  • 65
  • 192
  • 320

1 Answers1

1

I would go for the Web API. You said the client side interaction takes a big place in your project, and therefore should have its own project.

The main reason is separation of concerns, since its cleaner to separate the Controllers that return Html from the API that is used by the client side. Using a Web API project, that is dedicated for this particular subject will result a cleaner code.

For example, in MVC Controller, in order to return an object you will write the following code: return Json(customInstance); of type ActionResult. To achieve the same thing in WebAPI, will use this line of code: return customInstance; of type CustomObject.

Aviran Cohen
  • 5,581
  • 4
  • 48
  • 75