1 Using MVC 6. MVC vs. ASP Web Forms Both run under ASP.NET Can coexist In Web Forms, browser requests page. xxx.aspx and xxx.aspx.cs on the server Page.

Slides:



Advertisements
Similar presentations
Samsung Smart TV is a web-based application running on an application engine installed on digital TVs connected to the Internet.
Advertisements

INTRODUCTION TO ASP.NET MVC AND EXAMPLE WALKTHROUGH RAJAT ARYA EFECS - OIM DAWG – 4/21/2009 ASP.NET MVC.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Tutorial -01. Objective In this session we will discuss about : 1.What is MVC? 2.Why MVC? 3.Advantages of MVC over ASP.NET 4.ASP.NET development models.
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
An Introduction to ASP.NET Web Pages 2 Module 1: Webmatrix Installation and Your First Web Site Tom Perkins.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
JavaScript & jQuery the missing manual Chapter 11
ASP.NET Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
CSCI 6962: Server-side Design and Programming Introduction to Active Server Pages.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
MIS 3200 – C# (C Sharp)
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
C# Tutorial -1 ASP.NET Web Application with Visual Studio 2005.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
© Chinese University, CSE Dept. Distributed Systems / Simple Example Open Microsoft Visual Studio 2005:
Introduction to Web Services. Examples Using a Web Service Creating a new Web Service.
1 HTML Forms
Input & Output Functions JavaScript is special from other languages because it can accept input and produce output on the basis of that input in the same.
Introduction to MVC Introduction NTPCUG Tom Perkins, Ph.D.
Introduction to MVC Controllers NTPCUG Tom Perkins, Ph.D.
PART 2 INTRODUCTION TO DYNAMIC WEB CONTENT AND PHP.
Web Development in Microsoft Visual Studio 2013 / 2015.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
11 Getting Started with ASP.NET Beginning ASP.NET in C# and VB Chapters 1 and 2.
1111 Creating HTML Programatically Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML.
Introduction  “M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner.
1111 Master Pages Beginning ASP.NET in C# and VB Chapter 6.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
Virtual techdays INDIA │ 9-11 February 2011 SESSION TITLE Kamala Rajan S │ Technical Manager, Marlabs.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
BIT 286: Web Applications ASP.Net MVC. Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files.
11 jQuery Web Service Client. 22 Objectives You will be able to Use JSON (JavaScript Object Notation) for communcations between browser and server methods.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
How to develop a VoIP softphone in C# by using OZEKI VoIP SIP SDK This presentation demonstrates the first steps concerning to how to develop a fully-functional.
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
MIS 3200 – C# (C Sharp)
Jim Fawcett CSE686 – Internet Programming Spring 2014
ASP.NET Forms.
Chapter 2: The Visual Studio .NET Development Environment
An introduction to ASP.Net with MVC Nischal S
Unit 7 Learning Objectives
Jim Fawcett CSE686 – Internet Programming Spring 2012
Social Media And Global Computing Introduction to The MVC Pattern
Chapter 1: An Introduction to Visual Basic 2015
Data Virtualization Tutorial… CORS and CIS
Play Framework: Introduction
Create Virtual Directory Windows 8 - IIS 8.5
Setup Of 4050 EIP To Control LOGIX PLC
02 | Developing ASP.NET MVC 4 Models
Unit 27 - Web Server Scripting
Understanding the Visual IDE
1. Open Visual Studio 2008.
Lab 1 Introduction to C++.
Building ASP.NET Applications
Tutorial 7 – Integrating Access With the Web and With Other Programs
ASP.NET MVC Web Development
Security - Forms Authentication
Presentation transcript:

1 Using MVC 6

MVC vs. ASP Web Forms Both run under ASP.NET Can coexist In Web Forms, browser requests page. xxx.aspx and xxx.aspx.cs on the server Page life cycle. Web controls provide much prewritten code In MVC, browser requests a method in a class. The method produces a response HTML, JSON, other. 2

Getting Started You need Visual Studio 2015 ASP.NET 5 RC1 Microsoft tutorial Open Visual Studio

Create a new MVC 6 Application For an MVC application you must use New > Project Not New > Web Site 4

5 If you don't see this, you need to install ASP.NET RC _Install_ASP_NET_5_RC1.pdf Click OK

6

7

8 The default template gives you Home, Contact, About, Register, and Log in pages. Links in the black Nav bar at the top, if the window is wide enough. Nav bar

Same page in more narrow window 9 Nav bar Click here to expand Nav bar

Same Page with Nav Bar Expanded 10

MVC mvc-app/adding-controller.html#adding-a-controller mvc-app/adding-controller.html#adding-a-controller The MVC Pattern Model Data, "Business Rules", Program Logic View Presentation only Displays model data No program logic Controller Handles browser requests Invokes model functions 11

MVC The pattern encourages: Separation of concerns Loosely coupled components 12

In Visual Studio 13

Adding a Controller In Solution Explorer, right click on Controllers and select Add > New Item 14

Adding a Controller 15 Click Add

Controller Boilerplate 16 All controller class names end with "controller"

Replace the Boilerplate using Microsoft.AspNet.Mvc; using Microsoft.Extensions.WebEncoders; namespace MvcMovie.Controllers { public class HelloWorldController : Controller { // // GET: /HelloWorld/ public string Index() { return "This is my default action..."; } // // GET: /HelloWorld/Welcome/ public string Welcome() { return "This is the Welcome action method..."; } 17

Things to Notice 18 Default method invoked by appending /HelloWorld/ to the URL in a Get request Method invoked by appending /HelloWorld/Welcome/ to the URL in a Get request Every public method in a controller is callable from the browser. Let's try it!

Initial Page 19 Add /HelloWorld/ to the URL in the address box and press Enter.

Add /HelloWorld/ to the URL 20 Specifies the controller class

Output of the HelloWorldController 21

How it works MVC invokes controller classes (and the action methods within them) depending on the incoming URL. The default URL routing logic used by MVC uses a format like this to determine what code to invoke: /[Controller]/[ActionName]/[Parameters] The first URL segment detrmines to controller class to run. The second segment determines the action method to invoke within that class. We will discuss the thrid segment later. 22

Startup.cs You set the format for routing in the Startup.cs file. 23

Startup.cs 24 If you don't supply any URL segments, MVC uses default values: Home for controller Index for action

HelloWorldController Browse to The Welcome method in HelloWorldController.cs runs 25

Output of Welcome method in HelloWorldController 26

Passing Information to the Controller Let’s modify the example slightly so that you can pass some parameter information from the URL to the controller Example: /HelloWorld/Welcome?name=Scott&numtimes=4. 27

Passing Information to the Controller Change the Welcome method to include two parameters as shown below: public string Welcome(string name, int numTimes = 1) { return HtmlEncoder.Default.HtmlEncode( "Hello " + name + ", NumTimes is: " + numTimes); } Note that the code uses the C# optional-parameter feature to indicate that the numTimes parameter defaults to 1 if no value is passed for that parameter. The code above uses HtmlEncoder.Default.HtmlEncode to protect the app from malicious input (namely JavaScript). 28

Try it! 29

Controller Output 30 The MVC model binding system automatically maps the named parameters from the query string to parameters in the method. See Model BindingModel Binding

Another Way to Pass Data to the Controller Replace the Welcome method with the following code: public string Welcome(string name, int ID = 1) { return HtmlEncoder.Default.HtmlEncode( "Hello " + name + ", ID: " + ID); } 31

Another Way to Pass Data to the Controller 32 A third URL segment is specified this time. And only one query string.

Controller Output 33 This time the third URL segment matched the route parameter id. The Welcome method contains a parameter "id" that matched the URL template in the MapRoute method.

Recall the Route Setup The trailing ? (in id?) indicates that the id parameter is optional. 34

Summary In these examples the controller has been doing the “VC” portion of MVC Both the view and the controller work. The controller is returning HTML directly. Next we will look at using a Razor view template to help generate the HTML Response. 35