1 / 10

Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek

03 | Developing MVC 4 Controllers. Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek. Module Overview. Writing Controllers. Lesson 1: Writing Controllers and Actions.

lenka
Download Presentation

Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 03 | Developing MVC 4 Controllers Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek

  2. Module Overview • Writing Controllers

  3. Lesson 1: Writing Controllers and Actions • Responding to User Requests Writing Controller Actions Using Parameters Passing Information to Views Demonstration • Filters

  4. Responding to User Requests When an MVC web application receives a user request, the following events occur:

  5. Writing Controller Actions Writing a Controller action includes: • Create public method • Return a class that derives from ActionResult • Add parameters to the method • Insert code to perform the operation and return the result

  6. Using Parameters http://www.adventureworks.com/session/getsessionbytitle?title=MVC101 DefaultModelBinder publicActionResultGetSessionByTitle(stringtitle){ varquery = froms incontext.Sessions wheres.Title== title selects Photosession = query.FirstOrDefault(); return View("Details", session); }

  7. Passing Data to the View • Model • View(data) • Strongly typed, can be more flexible • More complex • ViewBag • Dynamic object for storing basic pieces of information • Alias for ViewData • Perfect for sending messages to the view • Only available for that action • Redirects cause the ViewBag to be emptied • TempData • Just like the ViewBag, but it’s also available on the next page

  8. How to Create a Controller

  9. What are Filters? Some requirements cut across logical boundaries are called cross-cutting concerns. Examples include: • Authorization • Logging • Caching There are four different types of filters: • Authorization filters run before any other filter and before the code in the action method • Action filters run before and after the code in the action method • Result filters run before and after a result is returned from an action method. • Exception filters run only if the action method or another filter throws an exception.

More Related