BIT 286: Web Applications ASP.Net MVC. Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Grid Wizard Enterprise Basic Tutorial Using Web Control Panel.
CakePHP. A framework for developing applications in PHP Inspired by Ruby on Rails Follows MVC design pattern Convention over configuration –No wheel reinventing.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
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.
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.
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
Introduction to Entity Framework Part 1 Tom Perkins NTPCUG.
Part 05 – Code First Migrations and Azure Deployment Entity Framework and MVC Series Tom Perkins NTPCUG.
® IBM Software Group © 2006 IBM Corporation The Eclipse Data Perspective and Database Explorer This section describes how to use the Eclipse Data Perspective,
ASP.NET MVC Tips and Tricks Al Wilkinson. Hi! I’m Al  First program in Logo in 1985 in 1st grade #loveatfirstbyte  Started HTML in 1996, led to web.
9-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Introduction to MVC Adding Model Classes NTPCUG Tom Perkins, Ph.D.
UC Berkeley Hello Rails. Review: MVC Goal: separate organization of data (model) from UI & presentation (view) by introducing controller –mediates user.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
INTRODUCTION TO DREAMWEAVER 8. What we already know…  Design basics  Contrast  Repetition  Alignment  Repetition  HTML.
Classroom User Training June 29, 2005 Presented by:
Server-side Scripting Powering the webs favourite services.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC - Models.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
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.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.
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.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Programming with Visual Web Developer Chapter 9.
Internet Technologies and Web Application Web Services With ASP.NET Tutorial: Introduction to.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
Using Xcode A Beginner’s Tutorial Erin Green. This tutorial will walk you through Xcode, a software development tool for Apple’s iOS applications – We.
MVC Concepts Basics Model-View-Controller (MVC) Concepts for Web Developers SoftUni Team Technical Trainers Software University
ASP.NET MVC Intro class MainContoller { function Index() {... raw data HTML CSS JavaScript REQUEST RESPONSE.
BIT 286: Web Applications Lecture 10 : Thursday, February 5, 2015 ASP.Net Form Submission.
ASP.NET MVC The Basic Big Picture Juhani Välimäki
Introduction to MVC Introduction NTPCUG Tom Perkins, Ph.D.
Introduction to MVC Controllers NTPCUG Tom Perkins, Ph.D.
Using oXygen 12 with XQuery Using oXygen to build and execute XQuery XQuery applications on eXist Date: April 2011 Dan McCreary President Dan McCreary.
Getting started with ASP.NET MVC Dhananjay
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
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.
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.
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.
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
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.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC - Models.
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
Jim Fawcett CSE686 – Internet Programming Spring 2014
ASP.NET Essentials SoftUni Team ASP.NET MVC Introduction
Introduction to .NET Florin Olariu
Asp.Net MVC Conventions
An introduction to ASP.Net with MVC Nischal S
Jim Fawcett CSE686 – Internet Programming Spring 2012
Social Media And Global Computing Introduction to The MVC Pattern
Play Framework: Introduction
SharePoint Cloud hosted Apps
Layout and Partial Views
5 Tips for Upgrading Reports to v 6.3
Controllers.
Layout and Partial Views
ASP.NET MVC Web Development
Chengyu Sun California State University, Los Angeles
Presentation transcript:

BIT 286: Web Applications ASP.Net MVC

Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files Passing info from controller to view: ViewBags Models Define a class that corresponds to a row in a DB table Define a custom connection string Start to grok the magic of Entity Framework (an ORM – Object-Relational Mapping layer)ORM – Object-Relational Mapping layer Bringing it all together Create a controller with full set of CRUD methods, including views. All ‘for free’ – VS does it for you!CRUD 2

MVC: Model-View-Controller (from Wikipedia)Wikipedia 3

MVP (MVC in CakePHP, ASP.Net MVC) 4 From Wikipedia

MVC Overview Model DB interaction: SELECT, UPDATE, etc Validation code View Renders web page Controller Receives input from prior page, decides what to do (including pulling stuff out of DB, storing stuff into DB, etc) Selects which View to then render Or redirect to another page, etc 5

First steps with a controller Basic game plan: walk through the following tutorials, with Fun Bonus Commentary by your professor tutorials/first-mvc-app/ tutorials/first-mvc-app/ 6

Getting started: New project, new controller New Project  Web  ASP.Net Web Application  Web Application MVC by default This will take a while VS seems to now “install a copy of everything locally” (vs. DLL Hell) Once that’s done then use the Debug  Start Debugging menu option Add a controller: Solution Explorer: right-click on ‘Controllers’ folder, select ‘Add’  New Item, then pick ‘MVC Controller Class’ Notice The new controller (“HelloWorldController”) The new view folder (“Views  HelloWorld”) 7

New Index, Welcome // GET: /HelloWorld/ public string Index() { return "This is my nifty action..." + DateTime.Now; // THIS IS BEING ESCAPED, INSTEAD OF FED TO THE BROWSER } // // GET: /HelloWorld/Welcome/ public string Welcome() { return "This is the Welcome action method..."; } Control+F5 to run the web app locally 8

Routing /[Controller]/[ActionName]/[Parameters] This is set up in the Startup.cs file: public void Configure(…) { // … app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } 9

URL-based Parameters to controller methods In the controller: public string Welcome(string name, int numTimes = 1) { return HttpUtility.HtmlEncode("Hello " + name + ", NumTimes is: " + numTimes); } Run your application and browse to the example URL ( 4)

Using the default ‘id’ parameter Try going to Notice that NumTimes is the default, 1 Change the controller code to public string Welcome(string name, int ID = 1) { return Microsoft.Extensions.WebEncoders.HtmlEncoder.Default.HtmlEncode( "Hello " + name + ", NumTimes is: " + ID); } Go back to Try going to Notice that ID is now three 11

Nicer URL We’re using a query string because the thing after ‘/Welcome’ didn’t match the {id} part of the format Let’s fix that now! routes.MapRoute( name: "Hello", url: "{controller}/{action}/{name}/{numTimes}" ); Go to /localhost:XXX/HelloWorld/Welcome/Scott/3 12

First steps with Views started/introduction/adding-a-view started/introduction/adding-a-view Generating web pages by concatenating HTML strings together is terrible You want the web designer people to be able to create beautiful HTML in Dreamweaver (etc)… ….while the developers can focus on the application logic. 13

Change the controller’s Index method: public ActionResult Index() { return View(); } In the Views folder, right-click and ‘Add Folder’, named HelloWorld. In Views  HelloWorld, right-click and select Add  New Item  MVC View Page, keep the default name (Index) 14

What to put in the View ViewData["Title"] = "Index"; } Index Hello from our View Template! Right click & “View In Browser” 15

Changing the layout affects ALL pages Change the app’s title in Views  Shared  _Layout.cshtml Layout == is where the page-specific stuff is put Change to “Your App’s Name” Notice how all the pages change 16

Views  _ViewStart.cshtml Common ‘header’ for all views Already defines the layout option Can change in your view file Or set to null to not have any layout 17

How to change this page’s individual ViewData["Title"] = “MY AWESOME INDEX"; } MY AWESOME INDEX Hello from our View Template! 18

Passing data from controller to view In Controllers  HelloWorld.cs… public IActionResult Welcome(string name, int numTimes = 1) { ViewData ["Message"] = "Hello " + name ; ViewData ["NumTimes"] = numTimes ; return View(); } 19 New file: Views  HelloWorld  ViewData["Title"] = "About"; } (int i = 0; } Go back to