asp net mvc controllers views l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
ASP.NET MVC: Controllers & Views PowerPoint Presentation
Download Presentation
ASP.NET MVC: Controllers & Views

Loading in 2 Seconds...

play fullscreen
1 / 37

ASP.NET MVC: Controllers & Views - PowerPoint PPT Presentation


  • 202 Views
  • Uploaded on

Todd Snyder Development Team Lead Infragistics Experience Design Group. Jess Chadwick Lead Code Monkey Infragistics Website Team. ASP.NET MVC: Controllers & Views. Model – View - Controller. Controller – The Traffic Cop. Handles User Input Interacts with Model/Data

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'ASP.NET MVC: Controllers & Views' - jeneil


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
asp net mvc controllers views

Todd Snyder

Development Team Lead

Infragistics Experience Design Group

Jess Chadwick

Lead Code Monkey

Infragistics Website Team

ASP.NET MVC: Controllers & Views

controller the traffic cop
Controller – The Traffic Cop
  • Handles User Input
  • Interacts with Model/Data
  • Select View to Render
controllers parameters
Controllers – Parameters
  • RouteData: Contains Name/Value Pairs
    • Form, Query String, and/or Cookie
    • Missing Reference/Nullable Types set to null
  • Nullable optional parameters
  • Base class: Request and Response Methods
controllers action results
Controllers – Action Results
  • ViewResult
  • RedirectResult
  • RedirectToRouteResult
  • ContentResult
  • JsonResult
  • EmptyResult
controllers attributes
Controllers – Attributes
  • PrincipalPermission
  • NonAction
  • ActionFilter
controllers action filters
Controllers– Action Filters
  • Attach additional behaviors to actions
    • Before & After Action Execution
    • Before & After Result Execution
  • Useful for logging, compression, etc.
testing controller actions
Testing Controller Actions
  • No requirement to test within ASP.NET runtime!
    • Use RhinoMocks, TypeMock, Moq, etc.
    • Create Test versions of the parts of the runtime you want to stub

[TestMethod]

public void ShowPostsDisplayPostView() {

TestPostRepository rep = new TestPostRepository();

BlogController controller = new BlogController(rep);

var result = controller.ShowPost(2);

Assert.AreEqual("showpost", result.ViewName);

Assert.IsTrue(repository.GetPostByIdWasCalled);

Assert.AreEqual(2, repository.LastRequestedPostId);

}

views what are they
Views – What are they?
  • Render output
  • Usually pretty “stupid”
views working with data
Views - Working with Data

It’s all about the “ViewData”

views strongly typed data
Views - Strongly-Typed Data
  • Inherits ViewPage<TModel>
  • DEMO: Strongly-Typed View
views weakly typed data
Views - Weakly-Typed Data
  • Inherits ViewPage
  • DEMO: Weakly-Typed View
view engines
View Engines

“I can see!”

view engines definition
View Engines - Definition
  • Figure out how to render the markup
    • View Locator finds the template
  • Pluggable
    • Web Forms, Nvelocity, Brail, Nhaml, etc.
  • Roll your own
    • Implement IViewEngine
view engines webformviewengine
View Engines - WebFormViewEngine
  • Default engine based on Web Forms markup
  • Familiar Environment
    • Layout: .master
    • Content: .aspx
    • User Controls: .ascx
view engines webformviewlocator
View Engines - WebFormViewLocator
  • Standard, default layout:

/Views

/{Controller Name}

/*.aspx

/*.ascx

/Shared

/*.master

/*.aspx

/*.ascx

ui helpers
UI Helpers

Think of them as your personal assistants.

why do we need ui helpers
Why do we need UI Helpers?
  • More control = less done for you
  • Avoid writing “boring” markup
  • Encapsulate what varies
  • Replace Web Forms server controls
extension methods revisited
Extension Methods Revisited
  • New .NET 3.0 feature
  • Static Methods posing as built-in behavior
  • Make your life a whole lot easier
  • Allow easy extensibility!
ui helpers common useful helpers
UI Helpers - Common/Useful Helpers

Form Helpers

Url/Link/Content Helpers

  • Html.Hidden()
  • Html.TextBox()
  • Html.TextArea()
  • Html.RadioButton()
  • Html.RadioButtonList()
  • Html.DropDownList()

method(name, value, attributes)

  • Html.ActionLink<T>()
  • Html.RouteLink()
  • Html.Encode()
  • Html.AttributeEncode()
  • Url.Action()
  • Url.RouteUrl()
  • Url.Encode(contentPath)
  • Url.Content(contentPath)
demo working with forms
DEMO: Working with Forms

No, not <form runat=“server”>…

Back to basics!

user controls
User Controls
  • Extension Methods
    • Html.RenderUserControl(virtualPath)
    • Html.RenderUserControl(virtualPath, data)
  • Server Controls
    • Traditional Web Forms style!
  • Third-Party Controls
  • DEMO: Create and use a user control
filling the gap
Filling the Gap
  • Roll your own
  • Popular Frameworks
    • jQuery
    • prototype
    • JavaScriptMVC
    • Rico
    • script.aculo.us
    • ASP.NET AJAX (client library)
  • DEMO: MVC & ASP.NET AJAX
q a thanks

Todd Snyder

Email:tsnyder@infragistics.com

Blog: http://blogs.infragistics.com/blogs/tsnyder

Q & A(thanks!)

Jess Chadwick

Email:jesschadwick@gmail.com

Blog: http://blog.jesschadwick.com

resources
Jess Chadwick

jesschadwick@gmail.com

http://blog.jesschadwick.com

Todd Snyder

tsnyder@infragistics.com

http://blogs.infragistics.com/blogs/tsnyder

Resources
  • The Bits
      • ASP.NET MVC Preview 3: http://asp.net/MVC
      • ASP.NET MVC Source Code:http://www.codeplex.com/aspnet
  • Quickstart
    • http://quickstarts.asp.net/3-5-extensions/mvc/default.aspx
  • Videos
    • ASP.NET: http://www.asp.net/learn/3.5-extensions-videos/
    • MIX: http://sessions.visitmix.com
  • Community/Blogs
      • ASP.NET Forums: http://forums.asp.net/1146.aspx
      • Scott Guthrie (ScottGu): http://weblogs.asp.net/scottgu/
      • Scott Hanselman: http://www.hanselman.com/blog/
      • Phil Haack: http://haacked.com/
    • Sample Apps
      • MVC Samples: http://www.codeplex.com/mvcsamples
      • CodeCampServer: http://codecampserver.org