SlideShare a Scribd company logo
1 of 34
MVC 4.0
Model View Controller
Slide created by Gigin Krishnan TG
Ggnlive.com
SAMPLE
PROJECT
MVC
PATTERN
MVC 4.0 FEATURES
Introduction to MVC
ASP.NET MVC is a framework for building web
applications
Model View Controller pattern to the ASP.NET
framework.
Created by GGN KRISHNAN
Features
 The Razor view engine
 Support for .NET 4 Data Annotations
 Improved model validation
 Greater control and flexibility with support for dependency
resolution and global action filters
 Better JavaScript support with unobtrusive JavaScript, jQuery
Validation, and JSON binding
 Use of NuGet to deliver software and manage dependencies
throughout the platform
Some of the top features in MVC 4.0 included
Introduction to MVC Pattern
The MVC separates the user interface (UI) of an application into three
main aspects
• The Model
• A set of classes that describes the data you’re working with as well as the business rules for how the data can be
changed and manipulated
• The View
• Defines how the application’s UI will be displayed
• The Controller
• A set of classes that handles communication from the user, overall application flow, and
application-specific logic
• It manages the relationship between the View and the Model
• It responds to user input, talks to the Model, and decides which view to render
CONTROLLER
Controllers within the MVC pattern are responsible for responding to user input
USER HTTP REQUEST CONTROLLER RESPONSE BROWSER
CONTROLLER
 Instead of having a direct relationship between the URL and a file
living on the web server’s hard drive, there is a relationship between
the URL and a method on a controller class.
 Each controller’s class name ends with Controller: ProductController,
Home Controller, and so on, and lives in the Controllers directory.
 Controllers in the MVC pattern are concerned with the flow of the
application, working with data coming in, and providing data going
out to the relevant view.
CONTROLLER
CONTROLLER ACTION
CONTROLLER ACTION
CONTROLLER
 The methods (Index, About, and Contact) within your controller are called
Controller Actions.
 They respond to URL requests, perform the appropriate actions, and return a
response back to the browser or user that invoked the URL.
Eg: http://7880/Home/About
http://7880/Home/Contact
Parameters in Controller Actions
 Actions by reacting to parameters that are passed in via the
URL
Eg: http://7880/Home/Contact?username= testname
Parameters in Controller Actions
 If your action method has a parameter named ID, then ASP.NET MVC
will automatically pass the URL segment to you as a Parameter
public string Details(string id)
{
string message = “User Details, Name = " + id.ToString();
return message;
}
Eg: http://7880/Home/Details/ testname
Summary
 Controllers are the conductors of an MVC application, tightly
orchestrating the interactions of the user, the model objects, and the
views.
 They are responsible for responding to user input, manipulating the
appropriate model objects, and then selecting the appropriate view
to display back to the user in response to the initial input.
VIEWS
 The view is responsible for providing the user
interface (UI) to the user
 The view transforms the data into a format ready to
be presented to the user
SPECIFYING A VIEW
 Views render the output for a specific action
 Views located in the views directory same as the name of the controller action
 the Views directory contains a folder per controller, with the same name as the
controller, but without the Controller suffix.
View Syntax
<html>
<head><title>Sample View</title></head>
<body>
<h1>Listing @items.Length items.</h1>
<ul>
@foreach(var item in items) {
<li>The item name is @item.</li>
}
</ul>
</body>
</html>
Adding a view
Adding a view
View Engine
 The Razor view engine was introduced with ASP.NET MVC 3 and is the default
view engine moving forward
 Razor was designed specifically as a view engine syntax. It has one main focus:
code-focused templating for HTML generation
 ASP.NET MVC includes two different view engines, the newer Razor view engine
and the older Web Forms view engine.
RAZOR ASPX
SPECIFYING A VIEW
 The key transition character in Razor is the “at” sign (@). This single character is
used to transition from markup to code and sometimes also to transition back
 An action method can return a ViewResult via the View method as follows
public class HomeController : Controller {
public ActionResult Index() {
ViewBag.Message = "Modify this template to jump-start
your ASP.NET MVC application.";
return View();
}
}
The view selected in this case would be /Views/Home/Index.cshtml.
SPECIFYING A VIEW
 The Index action to render a different view.
public ActionResult Index() {
ViewBag.Message = "Modify this template to jump-start
your ASP.NET MVC application.";
return View("NotIndex");
}
The view selected in this case would be /Views/Home/NotIndex.cshtml.
ViewData and ViewBag
ViewData
 To pass information from the controller to the view above
 You can set and read values using standard dictionary syntax, as follows:
ViewData["CurrentTime"] = DateTime.Now;
ViewBag
 The ViewBag is a dynamic wrapper around ViewData. It allows you to set
values as follows:
ViewBag. CurrentTime = DateTime.Now;
ViewBag. CurrentTime is equivalent to ViewData["CurrentTime"].
Layouts
Layouts in Razor help maintain a consistent look
and feel across multiple views within your
application
Layouts serve the same purpose as master pages
To define a common template for your site
Sample Layout
<!DOCTYPE html>
<html>
<head><title>@ViewBag.Title</title></head>
<body>
<h1>@ViewBag.Title</h1>
<div id="main-content">@RenderBody()</div>
<footer>@RenderSection("Footer")</footer>
</body>
</html>
Sample Layout
LAYOUT
VIEWS USING LAYOUTS
Using Layouts
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Partial View
An action method can also return a partial view
public class HomeController : Controller {
public ActionResult Message() {
ViewBag.Message = "This is a partial view.";
return PartialView();
}
}
Partial View using jQuery
 The following shows a very simple example using jQuery to load the
contents of a partial view into the current view using an AJAX call:
<div id="result"></div>
<script type="text/javascript">
$(function(){
$('#result').load('/home/message');
});
</script>
Creating an ASP.NET MVC 4 Application
Creating an ASP.NET MVC 4 Application
Select the View Engine
An overview to the structure of MVC Internet Application
Getting Started with MVC
Razor View Engine
Razor was designed specifically as a view engine syntax It has one main
focus: code-focused templating for HTML generation
Sample Code
@model MvcMusicStore.Models.Genre
@{ViewBag.Title = "Browse Albums";}
<div class="genre">
<h3><em>@Model.Name</em> Albums</h3>
<ul id="album-list">
@foreach (var album in Model.Albums)
{
<li>
<a href="@Url.Action("Details", new { id = album.AlbumId })">
<img alt="@album.Title" src="@album.AlbumArtUrl" />
<span>@album.Title</span>
</a>
Features
 The Razor syntax is easier to type, and easier to read
 Razor doesn’t have the XML-like heavy syntax of the Web
Forms view engine.
 Compact, expressive, and fluid
 Not a new language
 Razor is a syntax that lets you use your existing .NET coding skills in a template in a very intuitive way
Works with any text editor
Good IntelliSense

More Related Content

What's hot

Just a View: An Introduction To Model-View-Controller Pattern
Just a View:  An Introduction To Model-View-Controller PatternJust a View:  An Introduction To Model-View-Controller Pattern
Just a View: An Introduction To Model-View-Controller PatternAaron Nordyke
 
Sitecore MVC (London User Group, April 29th 2014)
Sitecore MVC (London User Group, April 29th 2014)Sitecore MVC (London User Group, April 29th 2014)
Sitecore MVC (London User Group, April 29th 2014)Ruud van Falier
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JSAkshay Mathur
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View EncapsulationJennifer Estrada
 
SUGCon 2014 Sitecore MVC
SUGCon 2014 Sitecore MVCSUGCon 2014 Sitecore MVC
SUGCon 2014 Sitecore MVCmikeedwards83
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe
 
Data controls ppt
Data controls pptData controls ppt
Data controls pptIblesoft
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsJennifer Estrada
 
ASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp PresentationASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp Presentationbuildmaster
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsRandy Connolly
 
Single page application 03
Single page application   03Single page application   03
Single page application 03Ismaeel Enjreny
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controlsRaed Aldahdooh
 
Esri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc FinalEsri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc Finalguestcd4688
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To MvcVolkan Uzun
 

What's hot (20)

Just a View: An Introduction To Model-View-Controller Pattern
Just a View:  An Introduction To Model-View-Controller PatternJust a View:  An Introduction To Model-View-Controller Pattern
Just a View: An Introduction To Model-View-Controller Pattern
 
Sitecore MVC (London User Group, April 29th 2014)
Sitecore MVC (London User Group, April 29th 2014)Sitecore MVC (London User Group, April 29th 2014)
Sitecore MVC (London User Group, April 29th 2014)
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
 
Actionview
ActionviewActionview
Actionview
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
 
Angular js 1.0-fundamentals
Angular js 1.0-fundamentalsAngular js 1.0-fundamentals
Angular js 1.0-fundamentals
 
SUGCon 2014 Sitecore MVC
SUGCon 2014 Sitecore MVCSUGCon 2014 Sitecore MVC
SUGCon 2014 Sitecore MVC
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
 
Data controls ppt
Data controls pptData controls ppt
Data controls ppt
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
ASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp PresentationASP.net MVC CodeCamp Presentation
ASP.net MVC CodeCamp Presentation
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server Controls
 
Single page application 03
Single page application   03Single page application   03
Single page application 03
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
Esri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc FinalEsri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc Final
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
 

Viewers also liked

Asp.net templated razor delegates
Asp.net templated razor delegatesAsp.net templated razor delegates
Asp.net templated razor delegatesLearningTech
 
SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4Jon Galloway
 
ASP.NET MVC One Step Deeper
ASP.NET MVC One Step DeeperASP.NET MVC One Step Deeper
ASP.NET MVC One Step DeeperEmad Alashi
 
Template Layout Overrides - a beginner's guide
Template Layout Overrides - a beginner's guideTemplate Layout Overrides - a beginner's guide
Template Layout Overrides - a beginner's guideRuth Cheesley
 
DDD Sydney 20111 Razor Session
DDD Sydney 20111 Razor SessionDDD Sydney 20111 Razor Session
DDD Sydney 20111 Razor SessionMohamed Meligy
 
Razor and the Art of Templating
Razor and the Art of TemplatingRazor and the Art of Templating
Razor and the Art of TemplatingJess Chadwick
 
What’s New and Hot in .NET 4.0
What’s New and Hot in .NET 4.0What’s New and Hot in .NET 4.0
What’s New and Hot in .NET 4.0Jess Chadwick
 
Asp.Net MVC - Razor Syntax
Asp.Net MVC - Razor SyntaxAsp.Net MVC - Razor Syntax
Asp.Net MVC - Razor SyntaxRenier Serven
 
Getting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and RazorGetting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and RazorDan Wahlin
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Dan Wahlin
 

Viewers also liked (14)

Asp.net templated razor delegates
Asp.net templated razor delegatesAsp.net templated razor delegates
Asp.net templated razor delegates
 
SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4
 
ASP.NET MVC One Step Deeper
ASP.NET MVC One Step DeeperASP.NET MVC One Step Deeper
ASP.NET MVC One Step Deeper
 
Views
ViewsViews
Views
 
Template Layout Overrides - a beginner's guide
Template Layout Overrides - a beginner's guideTemplate Layout Overrides - a beginner's guide
Template Layout Overrides - a beginner's guide
 
DDD Sydney 20111 Razor Session
DDD Sydney 20111 Razor SessionDDD Sydney 20111 Razor Session
DDD Sydney 20111 Razor Session
 
Razor and the Art of Templating
Razor and the Art of TemplatingRazor and the Art of Templating
Razor and the Art of Templating
 
Hadoop-BigData
Hadoop-BigDataHadoop-BigData
Hadoop-BigData
 
ASP.NET MVC 3
ASP.NET MVC 3ASP.NET MVC 3
ASP.NET MVC 3
 
Net 451 in action
Net 451 in actionNet 451 in action
Net 451 in action
 
What’s New and Hot in .NET 4.0
What’s New and Hot in .NET 4.0What’s New and Hot in .NET 4.0
What’s New and Hot in .NET 4.0
 
Asp.Net MVC - Razor Syntax
Asp.Net MVC - Razor SyntaxAsp.Net MVC - Razor Syntax
Asp.Net MVC - Razor Syntax
 
Getting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and RazorGetting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and Razor
 
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
 

Similar to Simple mvc4 prepared by gigin krishnan

Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handsonPrashant Kumar
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamentalldcphuc
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran Wahle
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introductionTomi Juhola
 
Building Modern Websites with ASP.NET by Rachel Appel
Building Modern Websites with ASP.NET by Rachel AppelBuilding Modern Websites with ASP.NET by Rachel Appel
Building Modern Websites with ASP.NET by Rachel Appel.NET Conf UY
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs WorkshopRan Wahle
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introductionFajar Baskoro
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC eldorina
 

Similar to Simple mvc4 prepared by gigin krishnan (20)

Session 1
Session 1Session 1
Session 1
 
Mvc
MvcMvc
Mvc
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
MVC Training Part 1
MVC Training Part 1MVC Training Part 1
MVC Training Part 1
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamental
 
MVC
MVCMVC
MVC
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Building Modern Websites with ASP.NET by Rachel Appel
Building Modern Websites with ASP.NET by Rachel AppelBuilding Modern Websites with ASP.NET by Rachel Appel
Building Modern Websites with ASP.NET by Rachel Appel
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
J2EE pattern 5
J2EE pattern 5J2EE pattern 5
J2EE pattern 5
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introduction
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
 

Recently uploaded

SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 

Recently uploaded (20)

SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 

Simple mvc4 prepared by gigin krishnan

  • 1. MVC 4.0 Model View Controller Slide created by Gigin Krishnan TG Ggnlive.com
  • 3. Introduction to MVC ASP.NET MVC is a framework for building web applications Model View Controller pattern to the ASP.NET framework. Created by GGN KRISHNAN
  • 4. Features  The Razor view engine  Support for .NET 4 Data Annotations  Improved model validation  Greater control and flexibility with support for dependency resolution and global action filters  Better JavaScript support with unobtrusive JavaScript, jQuery Validation, and JSON binding  Use of NuGet to deliver software and manage dependencies throughout the platform Some of the top features in MVC 4.0 included
  • 5. Introduction to MVC Pattern The MVC separates the user interface (UI) of an application into three main aspects • The Model • A set of classes that describes the data you’re working with as well as the business rules for how the data can be changed and manipulated • The View • Defines how the application’s UI will be displayed • The Controller • A set of classes that handles communication from the user, overall application flow, and application-specific logic • It manages the relationship between the View and the Model • It responds to user input, talks to the Model, and decides which view to render
  • 6. CONTROLLER Controllers within the MVC pattern are responsible for responding to user input USER HTTP REQUEST CONTROLLER RESPONSE BROWSER
  • 7. CONTROLLER  Instead of having a direct relationship between the URL and a file living on the web server’s hard drive, there is a relationship between the URL and a method on a controller class.  Each controller’s class name ends with Controller: ProductController, Home Controller, and so on, and lives in the Controllers directory.  Controllers in the MVC pattern are concerned with the flow of the application, working with data coming in, and providing data going out to the relevant view.
  • 9. CONTROLLER  The methods (Index, About, and Contact) within your controller are called Controller Actions.  They respond to URL requests, perform the appropriate actions, and return a response back to the browser or user that invoked the URL. Eg: http://7880/Home/About http://7880/Home/Contact
  • 10. Parameters in Controller Actions  Actions by reacting to parameters that are passed in via the URL Eg: http://7880/Home/Contact?username= testname
  • 11. Parameters in Controller Actions  If your action method has a parameter named ID, then ASP.NET MVC will automatically pass the URL segment to you as a Parameter public string Details(string id) { string message = “User Details, Name = " + id.ToString(); return message; } Eg: http://7880/Home/Details/ testname
  • 12. Summary  Controllers are the conductors of an MVC application, tightly orchestrating the interactions of the user, the model objects, and the views.  They are responsible for responding to user input, manipulating the appropriate model objects, and then selecting the appropriate view to display back to the user in response to the initial input.
  • 13. VIEWS  The view is responsible for providing the user interface (UI) to the user  The view transforms the data into a format ready to be presented to the user
  • 14. SPECIFYING A VIEW  Views render the output for a specific action  Views located in the views directory same as the name of the controller action  the Views directory contains a folder per controller, with the same name as the controller, but without the Controller suffix.
  • 15. View Syntax <html> <head><title>Sample View</title></head> <body> <h1>Listing @items.Length items.</h1> <ul> @foreach(var item in items) { <li>The item name is @item.</li> } </ul> </body> </html>
  • 18. View Engine  The Razor view engine was introduced with ASP.NET MVC 3 and is the default view engine moving forward  Razor was designed specifically as a view engine syntax. It has one main focus: code-focused templating for HTML generation  ASP.NET MVC includes two different view engines, the newer Razor view engine and the older Web Forms view engine. RAZOR ASPX
  • 19. SPECIFYING A VIEW  The key transition character in Razor is the “at” sign (@). This single character is used to transition from markup to code and sometimes also to transition back  An action method can return a ViewResult via the View method as follows public class HomeController : Controller { public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; return View(); } } The view selected in this case would be /Views/Home/Index.cshtml.
  • 20. SPECIFYING A VIEW  The Index action to render a different view. public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; return View("NotIndex"); } The view selected in this case would be /Views/Home/NotIndex.cshtml.
  • 21. ViewData and ViewBag ViewData  To pass information from the controller to the view above  You can set and read values using standard dictionary syntax, as follows: ViewData["CurrentTime"] = DateTime.Now; ViewBag  The ViewBag is a dynamic wrapper around ViewData. It allows you to set values as follows: ViewBag. CurrentTime = DateTime.Now; ViewBag. CurrentTime is equivalent to ViewData["CurrentTime"].
  • 22. Layouts Layouts in Razor help maintain a consistent look and feel across multiple views within your application Layouts serve the same purpose as master pages To define a common template for your site
  • 23. Sample Layout <!DOCTYPE html> <html> <head><title>@ViewBag.Title</title></head> <body> <h1>@ViewBag.Title</h1> <div id="main-content">@RenderBody()</div> <footer>@RenderSection("Footer")</footer> </body> </html>
  • 25. Using Layouts @{ Layout = "~/Views/Shared/_Layout.cshtml"; }
  • 26. Partial View An action method can also return a partial view public class HomeController : Controller { public ActionResult Message() { ViewBag.Message = "This is a partial view."; return PartialView(); } }
  • 27. Partial View using jQuery  The following shows a very simple example using jQuery to load the contents of a partial view into the current view using an AJAX call: <div id="result"></div> <script type="text/javascript"> $(function(){ $('#result').load('/home/message'); }); </script>
  • 28. Creating an ASP.NET MVC 4 Application
  • 29. Creating an ASP.NET MVC 4 Application
  • 30. Select the View Engine
  • 31. An overview to the structure of MVC Internet Application
  • 33. Razor View Engine Razor was designed specifically as a view engine syntax It has one main focus: code-focused templating for HTML generation Sample Code @model MvcMusicStore.Models.Genre @{ViewBag.Title = "Browse Albums";} <div class="genre"> <h3><em>@Model.Name</em> Albums</h3> <ul id="album-list"> @foreach (var album in Model.Albums) { <li> <a href="@Url.Action("Details", new { id = album.AlbumId })"> <img alt="@album.Title" src="@album.AlbumArtUrl" /> <span>@album.Title</span> </a>
  • 34. Features  The Razor syntax is easier to type, and easier to read  Razor doesn’t have the XML-like heavy syntax of the Web Forms view engine.  Compact, expressive, and fluid  Not a new language  Razor is a syntax that lets you use your existing .NET coding skills in a template in a very intuitive way Works with any text editor Good IntelliSense