SlideShare a Scribd company logo
www.softserve.ua
ASP.NET MVC 5. Part 1
Overview. Controllers. Views.
2014-11-25 by O. Shvets
Reviewed by O. Konovalenko
2www.softserve.ua
Agenda
● ASP.NET Architecture
● ASP.NET MVC 3, 4, 5
● Controllers
● Views
3www.softserve.ua
MVC Pattern
● Controller – application logic.
Communicate with user. It
receives and handles user
queries, interrupts with Model,
and returns results by View
objects
● Model – contains classes that
represent data, performs
operations with data-bases and
organizes relations between data-
classes.
● View – performs UI
representation. Works with
model.
4www.softserve.ua
ASP.NET Architecture
5www.softserve.ua
Lifecycle of an ASP.NET MVC 5
Application
6www.softserve.ua
Benefits of ASP.NET MVC
● Higher quality requirements
o Test Driven Development
● Cross platforms support
o Windows, PDA, IPhone, …
● HTML code control
● Clear ULR navigation
o http://musica.ua/groups/metallica
● Maintainable code and command work
7www.softserve.ua
What’s new in ASP.NET MVC 3
● Extensible Scaffolding with MvcScaffold integration
● HTML 5 enabled project templates
● The Razor View Engine
● Support for Multiple View Engines
● Controller Improvements
● JavaScript and Ajax
● Model Validation Improvements
● Dependency Injection Improvements
8www.softserve.ua
What’s new in ASP.NET MVC 4
● ASP.NET Web API
● Enhancements to Default Project Templates
● Mobile Project Template and Empty Project Template
● jQuery Mobile, the View Switcher, and Browser Overriding
● Task Support for Asynchronous Controllers
● Azure SDK
● Database Migrations
● Add Controller to any project folder
● Bundling and Minification
● Enabling Logins from Facebook and Other Sites Using
OAuth and OpenID
9www.softserve.ua
What’s new in ASP.NET MVC 5
● One ASP.NET project template
● ASP.NET Identity
● Bootstrap
● Authentication filters
● Filter overrides
● Attribute routing
10www.softserve.ua
What’s new in ASP.NET MVC 5.1 & 5.2
● New Features in ASP.NET MVC 5.1
o Attribute routing improvements
o Bootstrap support for editor templates
o Enum support in views
o Unobtrusive validation for MinLength/MaxLength Attributes
o Supporting the ‘this’ context in Unobtrusive Ajax
● New Features in ASP.NET MVC 5.2
o Attribute routing improvements
11www.softserve.ua
Create ASP.NET MVC 5 Application
12www.softserve.ua
Adding a Controller
13www.softserve.ua
Our New HelloWorldController
14www.softserve.ua
The App_Start/RouteConfig.cs File
15www.softserve.ua
Welcome Method with Parameters
16www.softserve.ua
Matching the Route Parameter
17www.softserve.ua
Passing Parameters As Route Data
● In ASP.NET MVC applications, it's more typical to pass in
parameters as route data than passing them as query
strings
18www.softserve.ua
URL Route Mapping Features
● You can include "-", ".", ";" or any other characters you want
as part of your route rules
o This would pass appropriate "language", "locale", and "category"
parameters to a ProductsController:
{language}-{locale}/products/browse/{category}
/en-us/products/browse/food
language=en, locale=us, category=food
o You can use the "." file extension type at the end of a URL to
determine whether to render back the result in either a XML or
HTML format
products/browse/{category}.{format}
/products/browse/food.xml category=food, format=xml
/products/browse/food.html category=food, format=html
19www.softserve.ua
Adding a View
20www.softserve.ua
The View
21www.softserve.ua
Layout Page
22www.softserve.ua
Layout Page
● The layout has access to the same properties the Razor
view has, including:
o AjaxHelper (through the Ajax property)
o HtmlHelper (through the Html property)
o ViewData and model
o UrlHelper (through the Url property)
o TempData and ViewContext
● To specify a layout inside a view, we can specify the layout
to use with the Layout property:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
23www.softserve.ua
Razor View Engine
● an alternative to the Web Forms view engine
● is responsible for rendering views in the Razor format
(either .cshtml files or .vbhtml files)
o The Web Form view engine is used to support the older-format
Web Form views (.aspx and .ascx files)
Web Forms view engine example:
<%@ Page Language="C#"
Inherits="System.Web.Mvc.ViewPage<Product[]>" %>
<ul>
<% foreach(var product in Model) { %>
<li><%: product.Name %></li>
<% } %>
</ul>
Razor view engine example
@model Product[]
<ul>
@foreach(var product in Model) {
<li>@product.Name</li>
}
</ul>
24www.softserve.ua
The Fundamentals of the Razor Syntax
● ‘@’ is the magic character that precedes code instructions
in the following contexts
o ‘@’ For a single code line/values
o ‘@{ … }’ For code blocks with multiple lines
o ‘@:’ For single plain text to be rendered in the page
<p>
Current time is: @DateTime.Now
</p>
@{
var name = “John”;
var nameMessage = "Hello, my name is " + name + " Smith";
}
@{
@:The day is: @DateTime.Now.DayOfWeek. It is a <b>great</b> day!
}
25www.softserve.ua
The Fundamentals of the Razor Syntax
● HTML markup lines can be included at any part of the
code:
● Razor uses code syntax to infer indent:
@if(IsPost){
<p>Hello, the time is @DateTime.Now and this
page is a postback!</p>
} else {
<p>Hello, today is: </p> @DateTime.Now
}
// This won’t work in Razor. Content has to be
// wrapped between { }
if( i < 1 ) int myVar=0;
26www.softserve.ua
Passing Data to the View
● There are three different ways to pass data to a view:
o by using the ViewDataDictionary,
o by using the ViewBag,
o by using strongly typed views.
27www.softserve.ua
ViewDataDictionary
● It isn’t recommended to use ViewDataDictionary
o You have to perform type casts whenever you want to retrieve
something from the dictionary.
28www.softserve.ua
ViewBag
● It isn’t recommended to use ViewBag
● The ViewBag provides a way to pass data from the
controller to the view
o It makes use of the dynamic language features of C# 4
● Set properties on the dynamic ViewBag property within
your controller:
● A ViewBag property is also available in the view:
29www.softserve.ua
Strongly Typed Views
● Views can inherit from two types by default:
o System.Web.Mvc.WebViewPage or
o System.Web.Mvc.WebViewPage<T>
● Class WebViewPage<T> provides a strongly typed wrapper
over ViewData.Model through the Model property and
provides access to strongly typed versions of the
associated view helper objects - AjaxHelper and
HtmlHelper
30www.softserve.ua
Adding a Model
31www.softserve.ua
Passing Model to the View
● By specifying the model type using the @model keyword,
view will inherit from WebViewPage<T> instead of
WebViewPage, and we will have a strongly typed view
public ActionResult Index()
{
//…
SomeModel model = new SomeModel();
return View(model);
}
<dl>
<dt>Name:</dt>
<dd>@Model.Name</dd>
<dt>Date Added:</dt>
<dd>@Model.DateAdded</dd>
<dt>Message:</dt>
<dd>@Model.Message</dd>
</dl>
32www.softserve.ua
● Partials are intended to render snippets of content
● If you find yourself copying and pasting one snippet of
HTML from one view to the next, that snippet is a great
candidate for a partial
● To render a partial we can use the RenderPartial method or
the Partial method in a parent view
33www.softserve.ua
Partial Views
● The partial name is used to locate the partial markup in the
locations:
o <Area><Controller><PartialName>.cshtml
o <Area>Shared<PartialName>.cshtml
o <Controller><PartialName>.cshtml
o Shared<PartialName>.cshtml
● In order to prevent accidentally using a partial view from an
action, we prefix the view name with an underscore
● Html.RenderPartial(...) renders the partial immediately to
the response stream
● Html.Partial(...) returns a string
o In Razor, Html.RenderPartial must be in a code block
34www.softserve.ua
?
Questions ?
Ad

More Related Content

What's hot (20)

MVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - IndiandotnetMVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - Indiandotnet
Indiandotnet
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
Surbhi Panhalkar
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
Er. Kamal Bhusal
 
Mvc
MvcMvc
Mvc
abhigad
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
Phuc Le Cong
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
Volkan Uzun
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
ravindraquicsolv
 
What's new in asp.net mvc 4
What's new in asp.net mvc 4What's new in asp.net mvc 4
What's new in asp.net mvc 4
Simone Chiaretta
 
Mvc fundamental
Mvc fundamentalMvc fundamental
Mvc fundamental
Nguyễn Thành Phát
 
Asp 1a-aspnetmvc
Asp 1a-aspnetmvcAsp 1a-aspnetmvc
Asp 1a-aspnetmvc
Fajar Baskoro
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
Ashton Feller
 
Dot net interview questions and asnwers
Dot net interview questions and asnwersDot net interview questions and asnwers
Dot net interview questions and asnwers
kavinilavuG
 
AngularJS = Browser applications on steroids
AngularJS = Browser applications on steroidsAngularJS = Browser applications on steroids
AngularJS = Browser applications on steroids
Maurice De Beijer [MVP]
 
ASP.NET MVC for Begineers
ASP.NET MVC for BegineersASP.NET MVC for Begineers
ASP.NET MVC for Begineers
Shravan Kumar Kasagoni
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
Ni
 
Mvc 4 0_jayant_jindal_28082010
Mvc 4 0_jayant_jindal_28082010Mvc 4 0_jayant_jindal_28082010
Mvc 4 0_jayant_jindal_28082010
Rishu Mehra
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
What is MVC?
What is MVC?What is MVC?
What is MVC?
Dom Cimafranca
 
MVC
MVCMVC
MVC
Iman Mehmandoust
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
Anton Krasnoshchok
 
MVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - IndiandotnetMVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - Indiandotnet
Indiandotnet
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
Volkan Uzun
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
ravindraquicsolv
 
What's new in asp.net mvc 4
What's new in asp.net mvc 4What's new in asp.net mvc 4
What's new in asp.net mvc 4
Simone Chiaretta
 
Dot net interview questions and asnwers
Dot net interview questions and asnwersDot net interview questions and asnwers
Dot net interview questions and asnwers
kavinilavuG
 
AngularJS = Browser applications on steroids
AngularJS = Browser applications on steroidsAngularJS = Browser applications on steroids
AngularJS = Browser applications on steroids
Maurice De Beijer [MVP]
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
Ni
 
Mvc 4 0_jayant_jindal_28082010
Mvc 4 0_jayant_jindal_28082010Mvc 4 0_jayant_jindal_28082010
Mvc 4 0_jayant_jindal_28082010
Rishu Mehra
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
Anton Krasnoshchok
 

Similar to ASp.net Mvc 5 (20)

ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamental
ldcphuc
 
Mvc
MvcMvc
Mvc
Furqan Ashraf
 
Technoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development services
Aaron Jacobson
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
Prashant Kumar
 
Marlabs - ASP.NET Concepts
Marlabs - ASP.NET ConceptsMarlabs - ASP.NET Concepts
Marlabs - ASP.NET Concepts
Marlabs
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
Volkan Uzun
 
AngularJS
AngularJSAngularJS
AngularJS
Maurice De Beijer [MVP]
 
ASP.Net | Sabin Saleem
ASP.Net | Sabin SaleemASP.Net | Sabin Saleem
ASP.Net | Sabin Saleem
SaBin SaleEm
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
People Strategists
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET Presentation
Rasel Khan
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
Prashant Kumar
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
Taranjeet Singh
 
Head first asp.net mvc 2.0 rtt
Head first asp.net mvc 2.0 rttHead first asp.net mvc 2.0 rtt
Head first asp.net mvc 2.0 rtt
Lanvige Jiang
 
MVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHatMVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHat
Scholarhat
 
MVC First Basic
MVC First BasicMVC First Basic
MVC First Basic
Shyam Sir
 
Introduction Asp.Net MVC5 |MVC5 Tutorial for Beginners & Advanced | Dot Net T...
Introduction Asp.Net MVC5 |MVC5 Tutorial for Beginners & Advanced | Dot Net T...Introduction Asp.Net MVC5 |MVC5 Tutorial for Beginners & Advanced | Dot Net T...
Introduction Asp.Net MVC5 |MVC5 Tutorial for Beginners & Advanced | Dot Net T...
Dot Net Tricks
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
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
Tuna Tore
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamental
ldcphuc
 
Technoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development services
Aaron Jacobson
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
Prashant Kumar
 
Marlabs - ASP.NET Concepts
Marlabs - ASP.NET ConceptsMarlabs - ASP.NET Concepts
Marlabs - ASP.NET Concepts
Marlabs
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
ivpol
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
Volkan Uzun
 
ASP.Net | Sabin Saleem
ASP.Net | Sabin SaleemASP.Net | Sabin Saleem
ASP.Net | Sabin Saleem
SaBin SaleEm
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET Presentation
Rasel Khan
 
Head first asp.net mvc 2.0 rtt
Head first asp.net mvc 2.0 rttHead first asp.net mvc 2.0 rtt
Head first asp.net mvc 2.0 rtt
Lanvige Jiang
 
MVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHatMVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHat
Scholarhat
 
MVC First Basic
MVC First BasicMVC First Basic
MVC First Basic
Shyam Sir
 
Introduction Asp.Net MVC5 |MVC5 Tutorial for Beginners & Advanced | Dot Net T...
Introduction Asp.Net MVC5 |MVC5 Tutorial for Beginners & Advanced | Dot Net T...Introduction Asp.Net MVC5 |MVC5 Tutorial for Beginners & Advanced | Dot Net T...
Introduction Asp.Net MVC5 |MVC5 Tutorial for Beginners & Advanced | Dot Net T...
Dot Net Tricks
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
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
Tuna Tore
 
Ad

Recently uploaded (20)

How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Ad

ASp.net Mvc 5

  • 1. www.softserve.ua ASP.NET MVC 5. Part 1 Overview. Controllers. Views. 2014-11-25 by O. Shvets Reviewed by O. Konovalenko
  • 2. 2www.softserve.ua Agenda ● ASP.NET Architecture ● ASP.NET MVC 3, 4, 5 ● Controllers ● Views
  • 3. 3www.softserve.ua MVC Pattern ● Controller – application logic. Communicate with user. It receives and handles user queries, interrupts with Model, and returns results by View objects ● Model – contains classes that represent data, performs operations with data-bases and organizes relations between data- classes. ● View – performs UI representation. Works with model.
  • 5. 5www.softserve.ua Lifecycle of an ASP.NET MVC 5 Application
  • 6. 6www.softserve.ua Benefits of ASP.NET MVC ● Higher quality requirements o Test Driven Development ● Cross platforms support o Windows, PDA, IPhone, … ● HTML code control ● Clear ULR navigation o http://musica.ua/groups/metallica ● Maintainable code and command work
  • 7. 7www.softserve.ua What’s new in ASP.NET MVC 3 ● Extensible Scaffolding with MvcScaffold integration ● HTML 5 enabled project templates ● The Razor View Engine ● Support for Multiple View Engines ● Controller Improvements ● JavaScript and Ajax ● Model Validation Improvements ● Dependency Injection Improvements
  • 8. 8www.softserve.ua What’s new in ASP.NET MVC 4 ● ASP.NET Web API ● Enhancements to Default Project Templates ● Mobile Project Template and Empty Project Template ● jQuery Mobile, the View Switcher, and Browser Overriding ● Task Support for Asynchronous Controllers ● Azure SDK ● Database Migrations ● Add Controller to any project folder ● Bundling and Minification ● Enabling Logins from Facebook and Other Sites Using OAuth and OpenID
  • 9. 9www.softserve.ua What’s new in ASP.NET MVC 5 ● One ASP.NET project template ● ASP.NET Identity ● Bootstrap ● Authentication filters ● Filter overrides ● Attribute routing
  • 10. 10www.softserve.ua What’s new in ASP.NET MVC 5.1 & 5.2 ● New Features in ASP.NET MVC 5.1 o Attribute routing improvements o Bootstrap support for editor templates o Enum support in views o Unobtrusive validation for MinLength/MaxLength Attributes o Supporting the ‘this’ context in Unobtrusive Ajax ● New Features in ASP.NET MVC 5.2 o Attribute routing improvements
  • 17. 17www.softserve.ua Passing Parameters As Route Data ● In ASP.NET MVC applications, it's more typical to pass in parameters as route data than passing them as query strings
  • 18. 18www.softserve.ua URL Route Mapping Features ● You can include "-", ".", ";" or any other characters you want as part of your route rules o This would pass appropriate "language", "locale", and "category" parameters to a ProductsController: {language}-{locale}/products/browse/{category} /en-us/products/browse/food language=en, locale=us, category=food o You can use the "." file extension type at the end of a URL to determine whether to render back the result in either a XML or HTML format products/browse/{category}.{format} /products/browse/food.xml category=food, format=xml /products/browse/food.html category=food, format=html
  • 22. 22www.softserve.ua Layout Page ● The layout has access to the same properties the Razor view has, including: o AjaxHelper (through the Ajax property) o HtmlHelper (through the Html property) o ViewData and model o UrlHelper (through the Url property) o TempData and ViewContext ● To specify a layout inside a view, we can specify the layout to use with the Layout property: @{ Layout = "~/Views/Shared/_Layout.cshtml"; }
  • 23. 23www.softserve.ua Razor View Engine ● an alternative to the Web Forms view engine ● is responsible for rendering views in the Razor format (either .cshtml files or .vbhtml files) o The Web Form view engine is used to support the older-format Web Form views (.aspx and .ascx files) Web Forms view engine example: <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Product[]>" %> <ul> <% foreach(var product in Model) { %> <li><%: product.Name %></li> <% } %> </ul> Razor view engine example @model Product[] <ul> @foreach(var product in Model) { <li>@product.Name</li> } </ul>
  • 24. 24www.softserve.ua The Fundamentals of the Razor Syntax ● ‘@’ is the magic character that precedes code instructions in the following contexts o ‘@’ For a single code line/values o ‘@{ … }’ For code blocks with multiple lines o ‘@:’ For single plain text to be rendered in the page <p> Current time is: @DateTime.Now </p> @{ var name = “John”; var nameMessage = "Hello, my name is " + name + " Smith"; } @{ @:The day is: @DateTime.Now.DayOfWeek. It is a <b>great</b> day! }
  • 25. 25www.softserve.ua The Fundamentals of the Razor Syntax ● HTML markup lines can be included at any part of the code: ● Razor uses code syntax to infer indent: @if(IsPost){ <p>Hello, the time is @DateTime.Now and this page is a postback!</p> } else { <p>Hello, today is: </p> @DateTime.Now } // This won’t work in Razor. Content has to be // wrapped between { } if( i < 1 ) int myVar=0;
  • 26. 26www.softserve.ua Passing Data to the View ● There are three different ways to pass data to a view: o by using the ViewDataDictionary, o by using the ViewBag, o by using strongly typed views.
  • 27. 27www.softserve.ua ViewDataDictionary ● It isn’t recommended to use ViewDataDictionary o You have to perform type casts whenever you want to retrieve something from the dictionary.
  • 28. 28www.softserve.ua ViewBag ● It isn’t recommended to use ViewBag ● The ViewBag provides a way to pass data from the controller to the view o It makes use of the dynamic language features of C# 4 ● Set properties on the dynamic ViewBag property within your controller: ● A ViewBag property is also available in the view:
  • 29. 29www.softserve.ua Strongly Typed Views ● Views can inherit from two types by default: o System.Web.Mvc.WebViewPage or o System.Web.Mvc.WebViewPage<T> ● Class WebViewPage<T> provides a strongly typed wrapper over ViewData.Model through the Model property and provides access to strongly typed versions of the associated view helper objects - AjaxHelper and HtmlHelper
  • 31. 31www.softserve.ua Passing Model to the View ● By specifying the model type using the @model keyword, view will inherit from WebViewPage<T> instead of WebViewPage, and we will have a strongly typed view public ActionResult Index() { //… SomeModel model = new SomeModel(); return View(model); } <dl> <dt>Name:</dt> <dd>@Model.Name</dd> <dt>Date Added:</dt> <dd>@Model.DateAdded</dd> <dt>Message:</dt> <dd>@Model.Message</dd> </dl>
  • 32. 32www.softserve.ua ● Partials are intended to render snippets of content ● If you find yourself copying and pasting one snippet of HTML from one view to the next, that snippet is a great candidate for a partial ● To render a partial we can use the RenderPartial method or the Partial method in a parent view
  • 33. 33www.softserve.ua Partial Views ● The partial name is used to locate the partial markup in the locations: o <Area><Controller><PartialName>.cshtml o <Area>Shared<PartialName>.cshtml o <Controller><PartialName>.cshtml o Shared<PartialName>.cshtml ● In order to prevent accidentally using a partial view from an action, we prefix the view name with an underscore ● Html.RenderPartial(...) renders the partial immediately to the response stream ● Html.Partial(...) returns a string o In Razor, Html.RenderPartial must be in a code block

Editor's Notes

  • #2: © Oleg Shvets, 2014.
  • #6: This document shows the lifecycle of every ASP.NET MVC application, beginning from receiving the HTTP request from the client to sending the HTTP response back to the client. It is designed both as an education tool for those who are new to ASP.NET MVC and also as a reference for those who need to drill into specific aspects of the application