AW Prepared and presented by : Muhammad Hesham & Mustafa Saeed Aspiration Webbers Session 5 (Asp.Net) Controller
•Reko Meets ASP.NET •What is ASP.NET •Architecture of MVC •Controller Objectives
ASP.NET Overview
What is MVC The MVC design pattern decouples the major components of an application allowing for efficient code reuse and parallel development.
Model,View,Controller Controller View Model
Every web application needs some structure MVC helps you to stay organized Often end up with less code, not more Smoother learning curve as your project growsmplicated, What’s the point? Seems complicated, What's the point?
Unit testing helps you change code with confidence ASP.NET MVC is designed to make unit test easy Testability
A controller is just a class No really it is just a class :D Controller
WWW.mywebsite.com/Album/Create public class AlbumController : Controller { } public ActionResult Create() { } Controller
public class AlbumController : Controller { public ActionResult Create() { } } Controller
ActionResult ActionResult ContentResult JavascriptResult JsonResult RedirectResult ViewResult
ActionResult Name Framework behivor Method Name ContentResult Returns a string literal Content JavaScriptResult Returns a script to execute Javascript JSONResult Returns data in json json RedirectResult Redirects the client to a new URL Redirect ViewResult Response is the responsibility of a view View / ParialView
//Test/ReturnContent public ContentResult ReturnContent() { return Content("Hello Heros"); } ContentResult
//Test/ReturnContent public ActionResult ReturnContent() { return Content("Hello Heros"); } ContentResult
// Test/ReturnJson public ActionResult ReturnJson() { return Json( new { name = "Reko", LastName = "MSP" }, JsonRequestBehavior.AllowGet); } JsonResult
//Test/ReturnNot public ActionResult ReturnNot() { return HttpNotFound("Sorry !!!"); } HTTP Code
//Test/ReturnHttpCode public ActionResult ReturnHttpCode() { return new HttpStatusCodeResult(500); } HTTP Code
// Test/ReturnFile public ActionResult ReturnFile() { return File(Server.MapPath( "~/Content/Site.css"), "text/css"); } Return a File
string Int Person Or anything !! Actions parameters
// Test/Search?name=Something public ActionResult Search(string name) { return Content(name); } Actions parameters
Actions attributes Action VerbAction Selector
[ActionName("Modify")] public ActionResult Edit() { return Content("Modify Action"); } Actions Selector //Test/Modify
Actions Verbs Get data form the server. Post data to the server. Update data on the server. Delete data from the server. [HttpPost] [HttpGet] [HttpPut] [HttpDelete]
[OutputCache] [Authorize] Actions Filters
Routes C M V www.mywebsite.com/album/create routes.MapRoute( name: "Default", url: "{controller}/{action}/{name}", defaults: new { controller = "Home", action = "Index", name = UrlParameter.Optional });
public ActionResult Search(string name) { return Content(name); } Routes
Demo
Contact : phmustafasaeed@outlook.com Muhammad.hesham7@outlook.com FB.com/groups/AWMSPCU17
Asp.net Overview and Controllers
Asp.net Overview and Controllers

Asp.net Overview and Controllers