ASP.NET MVC
public class TweetsController : Controller {
// GET: /Tweets/
[HttpGet]
public ActionResult Index() {
return Json(Twitter.GetTweets(), JsonRequestBehavior.AllowGet);
}
}
ASP.NET Web API
public class TweetsController : ApiController {
// GET: /Api/Tweets/
public List<Tweet> Get() {
return Twitter.GetTweets();
}
}
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.