Last post Apr 24, 2012 05:26 AM by imran_ku07
Apr 23, 2012 07:27 PM|IAsfour|LINK
I have more of a general question.
I am investigating the use of ApiController to possibly replace our MVC Controllers implementation. Since our MVC Controllers are used to render the view (via the various Actions), I am not if the ApiController will be a good replacement since it is mainly
meant to create REST services and not for web applications.
Do I have the general idea right here or am I completely wrong?
Looking for some input since documentation is kind of scarce out there.
Apr 23, 2012 07:45 PM|DarrellNorton|LINK
No, the two use different base classes that serve different purposes. You can see the difference just by looking at the types,
MVC Controller and
Here's a great quote from
Note 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 ApiController 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 data.
Apr 23, 2012 07:53 PM|IAsfour|LINK
Thanks for your reply.
I do understand that they are different types altogether but I am wondering about the general usage of each. We already know that MVC Controller are mainly used to receive HTTP Requests, do some logic and return a view or redirect to another page. That
is all clear to me. What is not clear is the intended usage of the Web API Controller. Is its purpose mainly to create REST services? Can a razr view post requests to an API Controller (not through ajax)?
Apr 23, 2012 10:01 PM|aliostad|LINK
Can a razr view post requests to an API Controller (not through ajax)?
Yes it can. In fact nothing stops you write an HtmlMediaTypeFormatter to implement this but it will probably be a lot of work. Your question is a valid one and is a common issue raised by the community. I can see these two to be unified perhaps in the next
version but not in this version.
But when it comes to the current version, you have to think if you are serving veiw or data: Use ASP.NET MVC to serve the views and use ASP.NET Web API to serve data,
Apr 24, 2012 05:26 AM|imran_ku07|LINK
What is not clear is the intended usage of the Web API Controller. Is its purpose mainly to create REST services? Can a razr view post requests to an API Controller (not through ajax)?
In fact nothing stops you write an HtmlMediaTypeFormatter to implement this but it will probably be a lot of work
Just wanted to make it clear that Media Type mainly depend upon mime type. This is why there is an built-in FormUrlEncodedMediaTypeFormatter(instead of HtmlMediaTypeFormatter).