In this tutorial, we are going to learn what is the difference between MVC controller and Web API Controller. This is also an interesting question of the interview.

Difference between An MVC Controller and Web API Controller.

There are following differences between an API Controller and MVC Controller.
  •  An API controller is derived from the API Controller class instead of Controller class.
  •  An API controller can not return view instead of they return serialized data whereas an MVC controller can return a view.
  • The Web API controller shows URL examples matching the default route pattern of “{controller}/{action}/{id}. Whereas MVC controller shows URL examples matching it’s default route pattern of {controller}/{action}/{id}”.

Best Practice:

  • In Web API Controller no need to convert data to JSON format.
  • User controller to render your normal views. API controller action only return data that is serialized and sent to the client
  • Whenever you are using ajax call use Web API controller.

View More:

Conclusion:

I hope you loved this post about the difference between MVC Controller and Web API Controller. Please don’t hesitate to comment in the comment box for any technical question.

 

Leave a Comment