Introduction to MVC 4 02. Controllers NTPCUG Tom Perkins, Ph.D.

Slides:



Advertisements
Similar presentations
1 FrontPage 2000 Online Tutorial The following tutorial aims to help you get started with FrontPage 2000 for the creation of basic web pages. The different.
Advertisements

Introduction to Java 2 Programming Lecture 4 Writing Java Applications, Java Development Tools.
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
XSL eXtensible Stylesheet Language. What is XSL? XSL is a language that allows one to describe a browser how to process an XML file. XSL can convert an.
Creating and Editing a Web Page Using Inline Styles
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Introduction to MVC Action Methods, Edit View, and a Search Feature NTPCUG Dr. Tom Perkins.
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.
Part 03 – Sorting, Paging, and Grouping Entity Framework NTPCUG Tom Perkins.
Razor. Slide 2 Remember this? Browser Web Server HTTP Request HTTP Response (Web page / code) Client code (script) Interpret request Generate HTML and.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
MIT AITI 2004 JSP – Lecture 2 Get and Post Requests.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Introduction to MVC Adding Model Classes NTPCUG Tom Perkins, Ph.D.
JavaScript & jQuery the missing manual Chapter 11
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - HelloWorld Application: Introduction to.
Part 06 – A More Complex Data Model Entity Framework and MVC NTPCUG Tom Perkins.
Creating a Web Site to Gather Data and Conduct Research.
E-Commerce: Introduction to Web Development 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics What is a Web.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
CS-4220 Dr. Mark L. Hornick1 Servlet configuration and deployment.
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.
CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
Website Development with PHP and MySQL Saving Data.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
© Chinese University, CSE Dept. Distributed Systems / Simple Example Open Microsoft Visual Studio 2005:
1 HTML Forms
Web App GUI: JSP Basics & Forms 3680 Enterprise Programming.
1 HTML Forms
Introduction to MVC Introduction NTPCUG Tom Perkins, Ph.D.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
1 Task 4 – Advanced Topics - Introduction  Chris Woyton  Support/Training 
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
1 HTML forms (cont.)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PART 2 INTRODUCTION TO DYNAMIC WEB CONTENT AND PHP.
Core basic Java web server technologies. Tools Eclipse IDE for Java EE Developers (Netbeans also works) nloads/packages/eclipse-
CSC 2720 Building Web Applications Basic Frameworks for Building Dynamic Web Sites / Web Applications.
Ruby on Rails Controller of MVC. Routes How we map URIs like /tweets/1 to calling the show method of the Controller.
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.
The Internet, Fourth Edition-- Illustrated 1 The Internet – Illustrated Introductory, Fourth Edition Unit B Understanding Browser Basics.
Creating and Editing a Web Page Using Inline Styles
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
BIT 286: Web Applications ASP.Net MVC. Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files.
Lesson 5 Introduction to HTML Forms. Lesson 5 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to.
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.
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.
Jim Fawcett CSE686 – Internet Programming Summer 2010
Jim Fawcett CSE686 – Internet Programming Spring 2014
An introduction to ASP.Net with MVC Nischal S
Jim Fawcett CSE686 – Internet Programming Spring 2012
Department of Computer Science
ASP MVP Web applications and Razor
Data Virtualization Tutorial… CORS and CIS
Play Framework: Introduction
Introduction to MVC PHP Web Development Ivan Yonkov Training Manager
MIS Professor Sandvig MIS 324 Professor Sandvig
Social Media And Global Computing Managing MVC with Custom Models
PHP and Forms.
ASP.NET MVC Web Development
MIS Professor Sandvig MIS 324 Professor Sandvig
Presentation transcript:

Introduction to MVC Controllers NTPCUG Tom Perkins, Ph.D.

The MVC Pattern Models: – Classes that represent the data of the app – Validation logic – Business Rules Views: – Template files used to generate HTML responses Controllers: – Handle requests to app – Retrieve Model data – Specify View templates to generate HTML response to user

Add a Controller Right-click the Controllers folder Select Add Controller

Name the Controller Name Leave alone Click

New file created (HelloWorldController.cs) New File Created

Replace the contents of the file: using System.Web; using System.Web.Mvc; namespace MvcMovie.Controllers { public class HelloWorldController : Controller { // // // GET: /HelloWorld/ // GET: /HelloWorld/ public string Index() public string Index() { return "This is my default action..."; return "This is my default action..."; } // // // GET: /HelloWorld/Welcome/ // GET: /HelloWorld/Welcome/ public string Welcome() public string Welcome() { return "This is the Welcome action method..."; return "This is the Welcome action method..."; } }

Information about HelloWorldController Has two methods Each method returns a string of HTML Run the app (Press F5 or Ctrl+F5) Append “HelloWorld” to the path in the address bar

Browser results Index (default) Method returns a string

MVC Address Format The Controller class (and method) that gets invoked depends on the incoming URL. Default format expected: – /[Controller]/[ActionName]/[Parameters] Example had no Action name (index is the default) Name of Controller class to execute Action (Method) to execute Any parameters required for executed method

Now, Browse to: We haven’t used Parameters yet

Let’s use some parameters Change the Welcome method: public string Welcome(string name, int numTimes = 1) { return HttpUtility.HtmlEncode("Hello " + name + ", NumTimes is: " + numTimes); } 2 parameters: name, numTimes Note C# default to 1 for numtimes

Change Welcome Method public string Welcome(string name, int numTimes = 1) { return HttpUtility.HtmlEncode("Hello " + name + ", NumTimes is: " + numTimes); }

Use this address in the browser:

The examples thus far: The controller has been acting as both the V + C in the MVC app – both Controller and View Usually, we don’t want to return a string directly to the user Next – Let’s use a separate View template to return some HTML …