Explain how asp.net mvc different from webforms
Web forms uses page controller or base controller design pattern where as MVC uses Front Controller design pattern.
Page Controller:
Page receives request from IIS and call controllers method. In traditional web forms all pages (View) inherit from System.Web.UI.Page class which has a code behind class acting as a controller.
Base Controller:
As a thumb of designing and architecture we should never inherit from base class directly and rather should provide a level of indirection by introducing our base types. In Base controller we create an abstract class that inherits from System.Web.UI.Page and use that as base class for all aspx pages.
Front Controller:
Controller received request from IIS and transfer to View. Controller has action methods which may return a view or any of available ViewResults defined below
Results returned by Action methods:
Actions in Asp.Net MVC returns ActionResult which is base class for all the results that can be returned. Below are classes that derive from ActionResult and can be returned as a result.
- ViewResult
- PartialViewResult
- ContentResult
- JsonResult
- JavascriptResult
- EmptyResult
- FileResult
- FilePathResult
- FileContentResult
- FileStreamResult
- HttpNotFoundResult
- HttpStatusCodeResult
- HttpUnAutorizedResult
- RedirectResult
- RedirectPermanentResult
- RedirectToActionResult
- RedirectToActionPermanentResult
- RedirectToRouteResult
- RedirectToRoutePermanentResult