ActionResult Types in MVC


Following table list ActionResult Types in MVC:


TypeHelperMethodDescription
ContentResultContent()Raw text data
EmptyResult--Returnsnothing
FileResultFile()Base class to send file
HttpUnauthorizedResult--Returns HTTP 401
JavaScriptResultJavaScript()Returns and executes script
JsonResultJson()JavaScript Object Notation
PartialViewResultPartialViewHTML snippet
RedirectResultRedirect()Redirect to URL
RedirectToRouteResultRedirectToRoute()
RedirectToAction()
Redirect to MVC route or action
ViewResultView()Full HTML page

The Tenets of MVC


Following are the tenets of MVC:


  • Separation of concerns
                      Foundation concept of a good application is that it should be modularized. So that each module focuses on its own module. In MVC, Model knows nothing about the View and the Controller. The View knows nothing about the Controller and so on. The more you keep the application separate the more it will perform better and it will be more maintainable. That's separation of concerns.
  • Convention over configuration
                    The ASP.NET MVC eliminates the need for extensive configuration settings by following various conventions. Example would be in MVC project has separate folders for Module, Views and Controller. Convention locations to locate code files that implement those different components. By keeping those component in convention folders you don't have to make extensive configuration changes.
  • Keep it DRY: Don't Repeat Yourself
                   DRY is one of the design principle that MVC embraces. The point here is you should reduce the duplication of code and logic which help in making the application faster as well as easier to maintaining. For example you can encapsulate chunk of reusable user interface code in partial view temples which are similar to asp.net user controls. 
  • Be helpful, but get out of the way
                 MVC allows you to have more control over HTML then ASP.NET web pages. It help you to fully customize the HTML view as per your need.

  

Recent Posts