Difference between controller and apicontroller in ASP.NET MVC

Difference between controller and apicontroller in ASP.NET MVC

A new feature introduced in ASP.NET MVC4 is Web API controller, which is very useful to pass and revive data from client to server and vice versa, lets see some of the difference between Controller and API controller.

If you have worked with ASP.NET MVC, then you are already familiar with controllers.
They work similarly in Web API, but controllers in Web API derive from the API controller class instead of Controller class.
The first major difference you will notice is that actions on Web API controllers do not return views, they return serialized data.
The MVC controller shows URL examples matching the default route pattern of “{controller}/{action}/{id}”.
The Web API controller shows URL examples matching it’s default route pattern of “api/{controller}/{id}”.
In Web API controller no need to convert data to json format.
Use Controller to render your normal views. API controller action only return data that is serialized and sent to the client.
when ever you are using ajax call use Web API controller.

Advertisements
This entry was posted in MVC and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s