What is difference between Web API Controller and MVC Controller ?
this question is asked in interview.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajkiran SwainRank #165 · 14.4K reputationPosted May 7, 2018, 5:19 AM EDT
geetha velusamy52 reputationPosted Nov 11, 2021, 9:25 AM EST
Asp.Net MVC is used to create web applications that return both views and data but Asp.Net Web API is used to create full-blown HTTP services with an easy and simple way that returns only data, not view. Web API helps to build REST-ful services over the MVC only return data in JSON format using JsonResult.
WebApiController:
//POST - Insert Data public IHttpActionResult PostNewCustomer(CustomerViewModel customer) { if (!ModelState.IsValid) return BadRequest("Invalid data. Please recheck1"); using (var x=new WebAPIDemo_DBEntities()) { x.customers.Add(new customer() { name = customer.Name, email = customer.Email, address = customer.Address, phone = customer.Phone }); x.SaveChanges(); } return Ok(); } MVC Controller: [HttpPost] public ActionResult Edit(CustomerMvcModel customer) { HttpResponseMessage response = GlobalVariables.webapiclient.PutAsJsonAsync("Customer/" + customer.Id, customer).Result; TempData["SuccessMessage"] = "Updated Successfully"; return RedirectToAction("Index"); }Vikas PanwarRank #1,447 · 1.1K reputationPosted Nov 12, 2021, 3:55 AM EST
Rijwan AnsariRank #82 · 24.2K reputationPosted Nov 12, 2021, 6:10 AM EST