Soe Tunhttp://geekswithblogs.net/stunTwitter: @SoeLinn
Soe Tun    American College of Cardiology (ACC)    Email: soelinn@gmail.com    Twitter: @SoeLinn    Blog: http://geeks...
ModelController           View
“Code Behind”  (Controller)Data Transfer Object(Model, View Model)HTML Template    (View)
routes.MapRoute(                                           name: “Default”,                                           url:...
Application Functionality
   User Interface     Consistency     Maintainability   Data Binding     Reliability     Security
Web Forms                         ASP.NET MVC   <asp:TextBox />                   Html.EditorFor(m => m.FirstName)     ...
Web Forms                                Ugly              Themes                          ClutteredASP.NET MVC
   Other HTML Helper methods     Html.TextBox(“FirstName”);     Html.DropDownList(“UidBloodType”);   Html.EditorFor( m...
ASP.NET MVC “Themes/Skins”
    Matched on System.Type Name      DateTime.ascx for DateTime    Using UIHintAttribute      [UIHint(“SelectionElemen...
Page_Load and Postback
Web Forms                                                                                                  ASP.NET MVCPati...
Web Forms                1. View Model                2. Data Binding                3. Server-Side Validation  ASP.NET MVC
T4 - Text Template Transformation Toolkit
   T4 Toolbox    o   http://t4toolbox.codeplex.com/   Microsoft SQL Server 2008 SDK       C:Program Files (x86)Microsof...
   Leave [Custom Tool] property empty for all    files with .t4 extension.
Model Metadata = Presentation + Validation
   Presentation         [DisplayName]              and      [Display].NET 4.0         [HiddenInput]       Validation  ...
   ASP.NET MVC 3     Built-in support for Validation Summary with jQuery     http://geekswithblogs.net/stun/archive/2011...
WebForms                        ASP.NET MVCWeb Controls               Html.EditorFor()Themes / Skins             Use Vie...
Thank you! Soe Tunhttp://geekswithblogs.net/stunTwitter: @SoeLinnEmail: soelinn@gmail.com
   Phil Haack    Custom Validation Attributes    http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx...
Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4
Upcoming SlideShare
Loading in …5
×

Retrofit Web Forms with MVC & T4

4,158 views

Published on

Presentation on ASP.NET MVC 3 for WebForms developers.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,158
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Retrofit Web Forms with MVC & T4

  1. 1. Soe Tunhttp://geekswithblogs.net/stunTwitter: @SoeLinn
  2. 2. Soe Tun  American College of Cardiology (ACC)  Email: soelinn@gmail.com  Twitter: @SoeLinn  Blog: http://geekswithblogs.net/stun/DC .NET User Group  Twitter: @dcdnug  2400 N St. NW DC 20037  http://dcdnug.org
  3. 3. ModelController View
  4. 4. “Code Behind” (Controller)Data Transfer Object(Model, View Model)HTML Template (View)
  5. 5. routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: new { controller = “Patient”, action = “Index” } ); Most Specific http://localhost/Patient/Index public ActionResult Index() { IList<Patient> model = GetPatients(); http://localhost/Patient/ PatientController Least Specific return View(“Index”, model); } http://localhost/Additional Infohttp://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspxhttp://www.asp.net/mvc/tutorials/asp-net-mvc-routing-overview-cshttp://haacked.com/archive/2010/02/12/asp-net-mvc-2-optional-url-parameters.aspx
  6. 6. Application Functionality
  7. 7.  User Interface  Consistency  Maintainability Data Binding  Reliability  Security
  8. 8. Web Forms ASP.NET MVC <asp:TextBox />  Html.EditorFor(m => m.FirstName)  Date  Number (int, decimal, ...)  String <asp:DropDownList />  Foreign Keys  Nullable<bool> <asp:CheckBox />  Boolean
  9. 9. Web Forms Ugly Themes ClutteredASP.NET MVC
  10. 10.  Other HTML Helper methods  Html.TextBox(“FirstName”);  Html.DropDownList(“UidBloodType”); Html.EditorFor( m => m.FirstName )  Strongly-Typed  Intellisense
  11. 11. ASP.NET MVC “Themes/Skins”
  12. 12.  Matched on System.Type Name  DateTime.ascx for DateTime Using UIHintAttribute  [UIHint(“SelectionElement”)] public int UidBloodType { get; set; } Brad Wilson – ASP.NET MVC 2 Templates (series) http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html
  13. 13. Page_Load and Postback
  14. 14. Web Forms ASP.NET MVCPatient model = service.GetPatient( id );PatientViewModel viewModel = Mapper.Map<Patient, PatientViewModel>(model);viewModel.RaceCheckBoxes = GetRaceSelections(model.UidPatient);viewModel.BloodTypes = new SelectList(service.GetBloodTypes(), "UidBloodType", "BloodTypeDesc", model.UidBloodType);return View("Edit", viewModel);
  15. 15. Web Forms 1. View Model 2. Data Binding 3. Server-Side Validation ASP.NET MVC
  16. 16. T4 - Text Template Transformation Toolkit
  17. 17.  T4 Toolbox o http://t4toolbox.codeplex.com/ Microsoft SQL Server 2008 SDK  C:Program Files (x86)Microsoft SQL Server100SDKAssemblies ▪ Microsoft.SqlServer.ConnectionInfo.dll ▪ Microsoft.SqlServer.Management.Sdk.Sfc.dll ▪ Microsoft.SqlServer.Smo.dll
  18. 18.  Leave [Custom Tool] property empty for all files with .t4 extension.
  19. 19. Model Metadata = Presentation + Validation
  20. 20.  Presentation  [DisplayName] and [Display].NET 4.0  [HiddenInput]  Validation  [StringLength]  [RegularExpression]Brad Wilson – ASP.NET MVC 2 Templates (series)http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.htmlhttp://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-4-custom-object-templates.html
  21. 21.  ASP.NET MVC 3  Built-in support for Validation Summary with jQuery http://geekswithblogs.net/stun/archive/2011/01/28/aspnet-mvc-3-client-side- validation-summary-with-jquery-validation-unobtrusive-javascript.aspx
  22. 22. WebForms ASP.NET MVCWeb Controls  Html.EditorFor()Themes / Skins  Use View TemplatesValidation  Attributes from Data Annotations View ModelsData Binding  and ViewData[“PropertyName”] = value;
  23. 23. Thank you! Soe Tunhttp://geekswithblogs.net/stunTwitter: @SoeLinnEmail: soelinn@gmail.com
  24. 24.  Phil Haack Custom Validation Attributes http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx Kazi Manzur Post-Redirect-Get (PRG) Pattern http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx http://weblogs.asp.net/rashid/archive/2009/04/03/asp-net-mvc-best-practices-part-2.aspx Martijn Boland Paging with ASP.NET MVC http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/ Note: I modified his code a little bit in my demo project.

×