Jim Fawcett CSE686 – Internet Programming Spring 2012

Slides:



Advertisements
Similar presentations
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
Advertisements

24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
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.
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
1 Chapter 12 Working With Access 2000 on the Internet.
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
ASP.NET Programming with C# and SQL Server First Edition
JQuery CS 268. What is jQuery? From their web site:
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
JavaScript & jQuery the missing manual Chapter 11
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Server-side Scripting Powering the webs favourite services.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
.Net is a collection of libraries, templates and services designed to make programming applications of all kinds, easier, more flexible (multi platform),
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
ASP.NET  ASP.NET is a web development platform, which provides a programming model, a comprehensive software infrastructure and various services required.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 4-1 of…
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active.
ASP.NET Controls. Slide 2 Lecture Overview Identify the types of controls supported by ASP.NET and the differences between them.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
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.
ASP.NET.. ASP.NET Environment ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. It is an easy.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.
Website Development with PHP and MySQL Saving Data.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
BIT 286: Web Applications Lecture 10 : Thursday, February 5, 2015 ASP.Net Form Submission.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Virtual techdays INDIA │ 9-11 February 2011 SESSION TITLE Kamala Rajan S │ Technical Manager, Marlabs.
Sergey Sidorov PhD student, computer software chair Computer Science department.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
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.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Form Submission And Saving Data To.
Jim Fawcett CSE686 – Internet Programming Summer 2010
Jim Fawcett CSE686 – Internet Programming Spring 2014
Jim Fawcett CSE686 – Internet Programming Spring 2014
ASP.NET Programming with C# and SQL Server First Edition
Asp.Net MVC Conventions
An introduction to ASP.Net with MVC Nischal S
Unit 9.1 Learning Objectives Data Access in Code
Social Media And Global Computing Introduction to The MVC Pattern
ASP MVP Web applications and Razor
Data Virtualization Tutorial… CORS and CIS
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Play Framework: Introduction
AJAX and REST.
Haritha Dasari Josue Balandrano Coronel -
CO6025 Advanced Programming
PHP / MySQL Introduction
Jim Fawcett CSE686 – Internet Programming Summer 2008
Introduction to Internet Programming
Unit 27 - Web Server Scripting
Chapter 23 – ASP.NET Outline 23.1 Introduction NET Overview
Controllers.
Static and Dynamic Web Pages
Web Development Using ASP .NET
Chapter 10 Accessing Database Files
Asp.Net MVC Conventions
Presentation transcript:

Jim Fawcett CSE686 – Internet Programming Spring 2012 Asp.Net mvc

What is Asp.Net MVC? Framework for building web applications Based on Model-View-Controller pattern Model manages the applications data and enforces constraints on that model. Often accessed through persistent objects Views are mostly passive presentations of application state. Views generate requests sent to a controller based on client actions. Controllers translate requests into actions on the data model and generate subsequent views.

MVC Life Cycle Clients request a named action on a specified controller, e.g.: http://localhost/aController/anAction The request is routed to aController’s anAction method. That method decides how to handle the request, perhaps by accessing a model’s state and returning some information in a view.

What is a Model? A model is a file of C# code and often an associated data store, e.g., an SQL database or XML file. The file of C# code manages all access to the application’s data through objects. Linq to SQL and Linq to XML create queries into these data stores This can be direct More often it is done through objects that wrap db tables or XML files and have one public property for each attribute column of the table.

One MVCGridDemos Model namespace MvcApplication2.Models { public class FileHandler public string path { get; set; } public string[] files { get; set; } public bool GetFiles(string pattern) try int pos = path.LastIndexOf("Home"); path = path.Substring(0, pos) + "Views\\Home"; files = System.IO.Directory.GetFiles(path); return true; } catch { return false; }

Adding a Model Right-click on Model folder and select Add Class. Populate the model class with public properties that represent data to be managed. Usually the model is persisted to an XML file or SQL database using LINQ or the Entity Data Framework.

What is a View? Views are usually aspx files with only HTML and inline code, e.g., <% … C# code here … %>. Code is used just to support presentation and does no application processing. The HTML is augmented by HTML Helpers, provided by Asp.Net MVC that provide shortcuts for commonly used HTML constructs. Asp.Net MVC comes with jQuery (Javascript) libraries to support reacting to client actions and doing AJAX communication with the server.

Views are results of actions class myController : controller { ActionResult someMethod(ModelClass model) { // possibly do something to model ViewData[“key”] = “a message”; return View(model); } }

Part of FormView <h2><%: ViewData["Message"] %></h2> <p/> <% using (Html.BeginForm("Form", "Home")) // args are method, controller { %> <div class="content"> <table> <tr><th>Parameter</th><th>Value</th></tr> <tr> <td>Name:</td> <td> <%= Html.TextBox(Html.Encode("Name"))%> </td> // more elements of form elided here

Script Blocks <% code to execute %> <%= string to write to Response %> <%: string to write to Response, gets HTML encoded %> <%$ AppSettings:Key %> <%# Eval(“Value”) %> renders bound property http://weblogs.asp.net/scottgu/archive/2010/04/06/new- lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and- asp-net-mvc-2.aspx http://michielvoo.net/blog/expressions-vs-statements- part-2-asp-net-code-block-types/

Html Helpers ActionLink: links to an action method BeginForm: links to action method rendering form for submit CheckBox DropDownList Hidden ListBox Password RadioButton TextArea TextBox

Adding a View Right-click on View folder select Add View and configure view from the resulting dialog. It’s easy to generate tables and lists that can be edited and posted back to the controller to effect changes to its model. The HTML helpers on the previous page make building a view a fairly simple process.

What is a Controller? A controller is a C# class that derives from the class Controller. A controller defines some category of processing for the application. Its methods define the processing details. Routing to a controller is defined in the Global.Asax.cs file. Its default processing is usually what you need.

Data Binding If a controller method takes a model class as a parameter, then the MVC infrastructure will instantiate an instance and pass to the controller method when requested via a url. On postback, if View parameters have the same names as model names, then the MVC infrastructure uses reflection to bind current view values to the model.

MVCGridDemos Controller Action methods [AcceptVerbs(HttpVerbs.Post)] public ViewResult Form(FormModel model) { ViewData["Message"] = "Form with model Postback"; if (string.IsNullOrEmpty(model.Name)) ViewData["NameError"] = true; else ViewData["NameError"] = false; // some checking code elided here // now, bind to the model and return to view return View(model); }

Action returns ActionResult ActionResult: base class ContentResult: user defined object to Response EmptyResult: Nothing to Response FileResult: Send binary file to Response RedirectResult: redirect to url RedirectToRouteResult: redirect using routes JasonResult: send json to Response JavaScriptResult: send Javascript to Response ViewResult: Render a view

Adding a Controller Right-click on the Controller folder and select Add Controller. Populate controller with methods whose names will become views and that take model parameters to supply views with data and react on postback to data changes made in view.

Web Application Development Create a new Asp.Net MVC project Delete any part of that you don’t need Add a controller for each category of processing in your application: A category is usually a few pages and db tables that focus on some particular application area Add methods to each controller for each request you wish to handle. Add views as needed for each controller action Add Model classes to support the application area: Each model class has public properties that are synchronized with data in the model db or XML file.

An Opinion This Asp.Net MVC structure is very flexible: You can have as many application categories as you need, simply by adding controllers. The controllers keep the application well organized. You can have as many views as you need. The navigation is simple and provided mostly by the MVC infrastructure, e.g., routing in Global.asax.cs. You can have as many models as you need. Just add classes and use Linq to access the data.

Things you need to know LINQ – Language integrated query Linq to XML and Linq to SQL are commonly used by models to provide data needed by a controller for one of its views. Jquery – Javascript Query library Jquery is frequently used by views to react to client actions in the browser. Jquery has facilities to use AJAX to retrieve small amounts of information from the server without loading a new view.

References Class Text: “Professional Asp.Net MVC 4” Asp.Net MVC Tutorials http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx http://nerddinnerbook.s3.amazonaws.com/Intro.htm Linq: http://dotnetslackers.com/articles/csharp/introducinglinq1.aspx Jquery http://docs.jquery.com/Tutorials:How_jQuery_Works#jQuery:_The_Basics

The End