Back to Questions

Best Practices in MVC application?

Your Answer

  • 12/18/2012 2:23:02 PM
  • Biju
  • 1

Best Practices in MVC application?

Some of the best practices in MVC applicaiton are:

  1. Avoid The New Keyword
  2. Avoid Referring To HttpContext Directly (use HttpContextBase)
  3. Avoid "Magic Strings"
  4. Using a strongly-typed model.
  5. Prefer models Over ViewData
  6. Do Not Write HTML In "back-end" Code
  7. Do Not Perform Business Logic In Views
  8. Consolidate Commonly-used View Snippets With Helper Methods
  9. Prefer Presentation Models Over Direct Usage Of Business Objects
  10. Encapsulate "if" Statements With HTML Helpers in Views
  11. Prefer Explicit View Names
  12. Prefer Parameter Objects Over Long Lists Of Parameters
  13. Encapsulate Shared/Common Functionality, Logic, And Data With Action Filters Or Child Actions (Html.RenderAction)
  14. Prefer grouping Actions into Controllers based on how they relate to business concepts
  15. Avoid grouping Actions into Controllers based on technical relation
  16. Prefer Placing Action Filters At The "highest appropriate level"
  17. Prefer The Post-Redirect-Get Pattern When Posting Form Data
  18. Prefer Startup Tasks Over Logic Placed In Application_Start (global.asax)
  19. Prefer Authorize Attribute Over Imperative Security Checks
  20. Prefer Using The Route Attribute Over More Generic Global Routes
  21. Consider Using An Anti-Forgery Token To Avoid CSRF Attacks
  22. Client Side: Call the Html.AntiForgeryToken helper method inside your form.
  23. Server Side: Apply the ValidateAntiForgeryTokenAttribute to the form post action.
  24. Consider the AcceptVerbs Attribute To Restrict How Actions May Be Called
  25. Consider Output Caching
  26. Consider Removing Unused View Engines
  27. Consider Custom ActionResult For Unique Scenarios
  28. Consider Asynchronous Controllers For Controller Tasks That Can Happen In Parallel

Reference : http://ofps.oreilly.com/titles/9781449320317/_best_practices.html

 

  • 12/18/2012 2:30:45 PM
  • test

Back to Questions