30
ASP.NET MVC Overview Presented By QuontraSolutions IT Courses Online Training Email:[email protected] Call Us: 404-900-9988

ASP.NET MVC Overview By QuontraSolutions

Embed Size (px)

DESCRIPTION

.Net Online Training in USA| Job Assistance .Net is a software development framework by Microsoft. Its use is extensive and reaches, immense. Its best feature is its language interoperability. It also is well known for performance, security, simplified deployment, memory efficiency etc. .Net programming skills are highly valued in the market and .Net programmers are always in demand. This might just be the skills that you need to move ahead and grow in your career. Contact us: http://www.quontrasolutions.com/asp-net-online-training-course.html Email: [email protected] Contact : 404-900-9988 - PowerPoint PPT Presentation

Citation preview

Page 1: ASP.NET MVC Overview By QuontraSolutions

ASP.NET MVC Overview

Presented By QuontraSolutions IT Courses Online Training

Email:[email protected] Call Us: 404-900-9988

Web:www.QuontraSolutions.com

Page 2: ASP.NET MVC Overview By QuontraSolutions

Agenda Beforehand – ASP.NET Web Forms What is MVC What is ASP.NET MVC? Models Views Controllers Validation Routing Unit Tests View engines

Page 3: ASP.NET MVC Overview By QuontraSolutions

ASP.NET Web Forms Rich controls and tools Postbacks Event driven web development Viewstate Less control over the HTML Hard to test Rapid development

Page 4: ASP.NET MVC Overview By QuontraSolutions

Let’s chat for a bit…

4

Page 5: ASP.NET MVC Overview By QuontraSolutions

Model – View - Controller

5

Controller - responsible for handling all user input

Model - represents the logic of the application

View - the visual representation of the model

Page 6: ASP.NET MVC Overview By QuontraSolutions

ASP.NET MVC More control over HTML No Codebehind Separation of concerns Easy to test URL routing No postbacks No ViewState

6

Page 7: ASP.NET MVC Overview By QuontraSolutions

Models The model should contain all of the

application business logic, validation logic, and database access logic.

ASP.NET MVC is compatible with any data access technology (for example LINQ to SQL)

All .edmx files, .dbml files etc. are located in the Models folder.

7

Page 8: ASP.NET MVC Overview By QuontraSolutions

Custom View Models

8

When you combine properties to display on a View

namespace ContosoUniversity.ViewModels{ public class AssignedCourseData { public int CourseID { get; set; } public string Title { get; set; } public bool Assigned { get; set; } }}

Page 9: ASP.NET MVC Overview By QuontraSolutions

Creating a Model - DEMO

9

Page 10: ASP.NET MVC Overview By QuontraSolutions

What is Controller? It is a class Derives from the base

System.Web.Mvc.Controller class Generates the response to the

browser request

10

public class HomeController : Controller{ public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!";

return View(); }

public ActionResult About() { return View(); }}

Page 11: ASP.NET MVC Overview By QuontraSolutions

Controller Actions Public method of the Controller

class Cannot be overloaded Cannot be a static method Returns action result

11

public ActionResult About(){

return View();}

Page 12: ASP.NET MVC Overview By QuontraSolutions

Action Results Controller action response to a

browser request Inherits from the base

ActionResult class Different results types

12

Page 13: ASP.NET MVC Overview By QuontraSolutions

Implement a Controller - DEMO

13

Page 14: ASP.NET MVC Overview By QuontraSolutions

Action Results Types ViewResult EmptyResult RedirectResult JsonResult JavaScriptResult ContentResult FileContentResult FileStreamResult FilePathResult

14

Page 15: ASP.NET MVC Overview By QuontraSolutions

Controller base class methods View

Redirect RedirectToAction RedirectToRoute Json JavaScriptResult Content File

15

Page 16: ASP.NET MVC Overview By QuontraSolutions

Views Most of the Controller Actions

return views The path to the view is inferred

from the name of the controller and the name of the controller action. \Views\ControllerName\

ControllerAction.aspx A view is a standard (X)HTML

document that can contain scripts. script delimiters <% and %> in the

views 16

Page 17: ASP.NET MVC Overview By QuontraSolutions

Pass Data to a View With ViewData:

ViewData["message"] = "Hello World!";

Strongly typed ViewData: ViewData.Model = OurModel;

With ViewBag:

ViewBag.Message = "Hello World!";

17

Page 18: ASP.NET MVC Overview By QuontraSolutions

Post data to a controller Verb Attributes

The action method in the controller accepts the values posted from the view.

The view form fields must match the same names in the controller.

18

[HttpPost]public ActionResult Edit(Movie movie){

if (ModelState.IsValid){

db.Entry(movie).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index");

}return View(movie);

}

Page 19: ASP.NET MVC Overview By QuontraSolutions

Explore a View - DEMO

19

Page 20: ASP.NET MVC Overview By QuontraSolutions

HTML Helpers Methods which typically return

string. Used to generate standard HTML

elements textboxes, dropdown lists, links etc. Example: Html.TextBox() method

Usage is optional You can create your own HTML

Helpers

Page 21: ASP.NET MVC Overview By QuontraSolutions

Validation Two types of validation error

messages generated before the HTML form

fields are bound to a class generated after the form fields are

bound to the class Model State Validation Helpers

Html.ValidationMessage() Html.ValidationSummary()

21

Page 22: ASP.NET MVC Overview By QuontraSolutions

Implement validation- DEMO

22

Page 23: ASP.NET MVC Overview By QuontraSolutions

Routing The Routing module is responsible

for mapping incoming browser requests to particular MVC controller actions.

Two places to setup: Web.config file Global.asax file

23

Page 24: ASP.NET MVC Overview By QuontraSolutions

Routing Setup Web.config file

24

<system.web><httpModules>

<system.web><httpHandlers>…

<system.webServer> <modules> …

<system.webServer> <handlers> …

Page 25: ASP.NET MVC Overview By QuontraSolutions

Routing SetupGlobal.asax file

25

public class MvcApplication : System.Web.HttpApplication{

public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home",

action = "Index", id = "" } );

}

protected void Application_Start() { RegisterRoutes(RouteTable.Routes); }}

Page 26: ASP.NET MVC Overview By QuontraSolutions

URL Example

http://www.mysite.com/Home/About/6

{controller} = Home {action} = About {id} = 6

26

Page 27: ASP.NET MVC Overview By QuontraSolutions

Unit Tests Used for the business logic (not

DAL or View logic). Test individual “unit”of code Make the code safe to modify Mock Object framework

When you lack “real” objects Create mocks for the classes in the

application Test with mock objects

27

Page 28: ASP.NET MVC Overview By QuontraSolutions

View Engines Handles the rendering of the view

to UI (html/xml); Different view engines have

different syntax ASP.NET MVC 3 Pre-included View

Engines: Web Forms Razor

28

Page 29: ASP.NET MVC Overview By QuontraSolutions

Things to remember What MVC stands for How ASP.NET MVC differs from Web

Forms Where is routing configured How to validate business logic How to use helpers Unit tests basics Choice between “View Engines”

29

Page 30: ASP.NET MVC Overview By QuontraSolutions

30

Thank You Attend Free Demo On .NET

Call Us: 404-900-9988 Email:[email protected]