Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

ASP.NET MVC

with examples
by

Rebecca Jacobsen

on 5 June 2014

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of ASP.NET MVC

Controller
Model
View
presentation
http://OBD/DEQToo/Search
application logic
business logic,
state, & behavior
public class DEQTooController
public ActionResult Search()
public class
VinOrPlateInputToSearchFor
Search.cshtml
Request
Instantiate and use
Returns a View with the model class as argument
How does it work ?
What is MVC?
MVC is not Web Forms
Starts with routing
Parts are loosely coupled
Advantages of MVC
Design Considerations
Internation-alization
Take away
ASP.NET MVC
Full control over HTML output
Testability and TDD
Serving methods, not files
Fat, Dumb, Thin
Use MVC for larger more complex projects
Divides into simpler, manageable components: less complexity
Modular, so works better for large teams
Easy integration with Javascript, CSS, AJAX, etc.
More control over application behavior and over rendered HTML
Better Search Engine Optimization (SEO)
Ease of testing (and TDD)
Flexible and maintainable - separation of concerns (SoC)
You can have multiple forms on a page
WebForms Advantages
Easier to learn
Abstracts the Web machinery
Third party controls available (drag-and-drop)
Speed of Development (automatic plumbing)
Familiar event-driven programming style
Server-side dynamic web page framework built on asp.net and supporting:
Separation of concerns
TDD
URL routing
Serving methods, not files (no code behind)
Use Object Oriented Design Principles
With example
code
Display
User input/output
Fat, Dumb, Thin
Fat: Model
Dumb: View
Thin: Controller
Has business rules
Fat Model
Application data (properties and session data)
Has domain specific objects
Stores state
Data validation logic
Output and presentation
Dumb View
May use master pages and partial views
May access model classes for presentation purposes only
HTML
Json
JavaScript
Thin Controller
Handles user requests
Tells model and view what to do
Applies appropriate routing logic for handling user requests
No Database access
No markup
No business logic
No application logic
Note!
MVC does not replace Web Forms
MVC and Web Forms can co-exist in the same application

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home",
action = "Index", id = UrlParameter.Optional }
);
Controller directs
[HttpGet]
public ActionResult Search()
{
VinOrPlateInputToSearchFor input =
new VinOrPlateInputToSearchFor();
return View(input);
}
File
View
Redirect
PartialView
Routing
Controller
View displays
View
@model DEQTooCore.Models.VinOrPlateInputToSearchFor
@using (Html.BeginForm("Search", "DEQToo", FormMethod.Post))
{
@Html.EditorFor(model => model.InputField)
<input type="submit" value="Search" />
}
.
.
.
Both use Roles, Membership, Authentication, and the classes and methods of asp.net
Convention over configuration
Exception handling
Authentication, authorization
Output caching
Object Oriented Design
SRP - Single Responsibility Principle
OCP - Open Closed Principle
DIP - Dependency Inversion Principle
ISP - Interface Segregation Principle
LSP - Liskov's substitution principle
IOC - Inversion of control
DRY - Don't repeat yourself
Motivation...
Hello Razor!
Silly, but memorable
Accesses the Database
All strings are in resource files
Greedy matching
Maps URL to action
Can ignore URLs with IgnoreRoute
Can call MapRoute multiple times, order is important
routes.MapRoute(
"Localization",
"{culture}/{controller}/{action}/{id}",
new { controller = "Home", action = "Index",
id = UrlParameter.Optional },
new { culture = "(en|es)" }
).RouteHandler = new CultureRouteHandler();
Route
registered before the default route
var ci = new CultureInfo("es");
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(ci.Name);
Override GetHttpHandler
Derived from MvcRouteHandler
Changing culture
@foreach (var c in
DEQWeb.Helpers.CultureHelper.Cultures)
{
@Html.ActionLink(
c.LanguageName,
"ChangeCulture",
new { lang = c.CultureCode,
returnUrl =this.Request.RawUrl },
new { @class = "culture-link" })
<span style="color:#474747;">|</span>@:&nbsp;
}
Make links to change culture
Click, change culture
Rebecca
Jacobsen
/
/OBD
/OBD/en/DEQToo/Search
/OBD/en
/OBD/DEQToo/Search
/es
/OBD/es
/OBD/es/DEQToo/Search
/OBD/es
/OBD/es/DEQToo/Search
http://OBD/DEQToo/ChangeCulture?lang=es&returnUrl=/DEQToo/Search
DEQToo controller, ChangeCulture method
which changes returnUrl from /DEQToo/Search to /es/DEQToo/Search
Redirect(returnUrl)
Full transcript