Here is my Controller -
namespace MvcApplication.Controllers
{
public class HomeController : Controller
{
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
public JsonResult GetPartNumbers()
{
var PartNumbers = ProductModel.LoadAllPartNumbers().ToArray();
return Json(PartNumbers, JsonRequestBehavior.AllowGet);
}
}
}
I haven't inherited from ApiController. Still it's working as it can return ActionResult data types for MVC requests as well as basic data types for api requests. Here is my WebApiConfig file -
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
I am using MVC4. Now the main question is how come this working as i have not inherited from ApiController, and then what is the need of ApiController if this can work?
EDIT
public bool SaveEvent(string PartNumber, string DateTimeScheduled, string DateTimeEnd, string Notes, string PSI)
{
return DiaryEvent.CreateNewEvent(PartNumber, DateTimeScheduled, DateTimeEnd, Notes, PSI);
}
This above method does not return an ActionResult, but a primitive type but this is called via ajax and can return bool true or false