ASP.NET MVC Best practices

2,738 views
2,620 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,738
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
60
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\ItemTemplates\\CSharp\\Web\\MVC 2 <h2><#= mvcHost.ViewName #></h2>
  • ASP.NET MVC Best practices

    1. 1. HattanShobokshi<br />ASP.NET MVC Best Practices<br />
    2. 2. Housekeeping<br />Stuttering is a communication disorder involving disruptions, or “disfluencies,” in a person’s speech.<br />Across all cultures, roughly 1% of people currently has a stuttering disorder.<br />http://westutter.org/<br />
    3. 3. HattanShobokshi<br />Senior Software Engineer<br />www.hattanshobokshi.com<br />hattan@gmail.com<br />http://speakerrate.com/hattanhttp://www.slideshare.net/shobokshi<br />Who am I?<br />
    4. 4. Look at Examples of BAD CODE<br />PRG Pattern<br />Load JavaScript files from CDN<br />Do not Include view formatting in the controller<br /> T4 Templates<br /> Custom View & Controller Templates<br /> Diagnostic Tools <br />Telerik Grid Control<br />Goals for this talk<br />
    5. 5. PRG Pattern<br />HTTP POST<br />Redirect<br />HTTP GET<br />The prg pattern is used to ensure that the intended modification of data only happens once.<br />
    6. 6. Content Delivery Network<br />Improve Application Performance<br />Reuse Javascript files Cached by different domains<br />Available Content Files:<br />jQuery<br />jQuery Validation<br />jQuery UI<br />Ajax Control Toolkit<br />ASP.NET Ajax<br />ASP.NET MVC JavaScript Files <br />http://www.asp.net/ajaxlibrary/cdn.ashx<script src='http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js' type='text/javascript'></script> <br />Microsoft AjaxContent Delivery Network <br />
    7. 7. T4 : Text Template Transformation Toolkit<br />Code Generation Tool<br /> Built into Visual Studio (2008 and 2010)<br />.tt File Extension<br /> No syntax highlighting by default<br />Clarius Visual T4 Add-onhttp://www.visualt4.com/<br />Tip: Windows 7/Vista unblock zip file, unblock individual files<br /> More informationhttp://www.olegsych.com/2007/12/text-template-transformation-toolkit/<br />
    8. 8. T4MVC<br />T4 template for ASP.NET MVC<br />Creates strongly typed helpers<br />Eliminates magic strings (View names, HtmlHelper parameters)<br />Download via NuGet or<br />http://mvccontrib.codeplex.com/wikipage?title=T4MVC<br />http://blogs.msdn.com/b/davidebb/archive/2010/03/12/a-better-way-to-auto-run-t4mvc-when-you-build.aspx<br />
    9. 9. T4MVC<br /><%= Html.ActionLink(“New Dinner", “Create", "Dinners")%><br /><%= Html.ActionLink(" New Dinner", MVC.Dinners.Create())%><br /><imgsrc="/Content/nerd.jpg" /><br /><imgsrc="<%= Links.Content.nerd_jpg %>" /><br />http://mvccontrib.codeplex.com/wikipage?title=T4MVC_doc<br />
    10. 10. Custom Tooling<br />Customize Default View Templates<br />Add new View Templates<br />Customize Controller Template<br />T4 Templates<br />~Microsoft Visual Studio 10.0Common7IDEItemTemplatesCSharpWebMVC 2<br />~Microsoft Visual Studio 10.0Common7IDEItemTemplatesVisualBasicWebMVC 2<br />T4 Code Templates<br />
    11. 11. Add Reference to Dll<br />Enable route debugging with 1 line of codeRouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);<br />http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx<br />Route Debugger<br />
    12. 12. MVC Diagnostics<br />Environment Information<br />MVC Assembly Version<br />Referenced Assembly Information<br />Web Forms page, not an mvc page<br />http://bradwilson.typepad.com/blog/2010/03/diagnosing-aspnet-mvc-problems.html<br />
    13. 13. Telerik Grid Control<br />http://demos.telerik.com/aspnet-mvc/<br />Grid Control<br />Out of the box support for Sorting, Filtering<br />Out of the box paging support<br />Out of the box ajax support<br />Very little javascript you have to write! <br />
    14. 14. What did we just talk about?<br />Look at Examples of BAD CODE<br />PRG Pattern<br />Load JavaScript files from CDN<br />Do not Include view formatting in the controller<br /> T4 Templates<br /> Custom View & Controller Templates<br /> Diagnostic Tools <br />Telerik Grid Control<br />
    15. 15. Contact Information<br />Email: hattan@gmail.com<br />www.hattanshobokshi.com<br />
    16. 16. The End<br />Thank you!<br />

    ×