SlideShare a Scribd company logo
ASP.NET MVC
Training – Part 2
AN ASP.NET MVC INTRODUCTION
Lee Englestone (@LeeEnglestone)
Tech Lead @ Kitbag.com
www.ManchesterDeveloper.com
Areas
 Areas group related Models, Views and
Controllers
 By default no Areas exists
 They appear in the route like so
 http://www.website.com/{Area}/{Controller}/{Action}/{Id}
 You can try adding an Area to your application and you’ll see
it creates a new folder and sub-folders for Models, Views and
Controllers and the code to register the Area itself
 We don’t use Areas
HtmlHelpers
 HtmlHelpers are methods that can be executed
within Razor views to generate HTML
 They are actually just extension methods and
therefore you can write your own HtmlHelper
methods
 The @Html.Action Helper method can be used to
generate links given controller, actions names
and id values
 We’ve already encountered @Html.LabelFor()
and @Html.TextBoxFor() in Part 1
Partial Views
 A view that can be rendered in another view
 Conceptually similar to WebForms UserControls
 By convention located in the Views/Shared folder
 By convention prefixed with an underscore
 Can be returned from Controller Actions with a
Model
Next we’ll create a partial view
that returns a picture of a cat
Exercise : Create and use
a simple Partial View
 Create a new PartialView at
Views/Shared/_FunnyCat.cshtml
 Put an image of a funny cat in /Images
 Update _FunnyCat.cshtml
 Add @Html.Partial(“FunnyCat”, “Steve”) to
Index.html
 Run
Custom Mobile Views
using DisplayModes
 Rules can be put into place to serve different
views with different extensions in different
circumstances
 A popular method is that if a user has requested a
page on a mobile device and there are 2 versions
of a View in the View folder
 Index.cshtml
 Index.mobile.cshtml
 Then the relevant view will be returned
 There is a built in DisplayMode for *.mobile.cshtml
views
Exercise : Create Mobile View
 Create a new View called
ViewsIndex.mobile.cshtml
 Make it obvious it is the Mobile View
 Run the application and emulate a Mobile
device
CSS Boostrap Framework
 Bootstrap is a popular CSS and JavaScript
framework that now is included in / used by new
ASP.NET MVC Application projects
 http://getbootstrap.com/
 It warrants a training course in itself (so check it
out) but some of main things it gives are
 Browser reset
 Grid system
 Glyphicons
 Popovers, tooltips, tabs, modals, pagination
Dependency Injection
 A way of objecting dependencies
 Generally speaking we use Constructor Injection
Constructor Injection
Exercise : Dependency Injection
 Add Ninject to MVC Application using NuGet
 Creates App_Start/NinjectWebCommon.cs
Mappings can be put here in the format
kernel.Bind<ISomeInterface>().To(SomeClass);
TDD/Unit Testing
 Controllers can be easily Unit Tested
 Can mock dependencies
 A few things you could Unit Test
 The View (or result) returned from an Action is of the
correct type
 The Model returned from an Action is correct
Exercise : Unit Testing Controllers
 Create a new ClassLibrary called Tests and
Reference NUnit using NuGet
 Add a reference in the class library to the Web
Application
 Create a new File called HomeControllerTests.cs
 Assert that the Type of Model returned from the
Index View on the controller is HomeViewModel
Bundling
 The merging together and serving of multiple files
 Instead of a request for each javascript/css file,
files are ‘merged together’ to reduce number of
requests
 Bundles defined in App_Start/BundleConfig.cs
 Can be turned off whilst debugging / working
locally
Bundling
Minification
 The removing of whitespace in served javascript
and css files
 Is done automatically to styles and scripts in a
Bundle
 Can be turned off whilst debugging / working
locally
Scaffolding Views
 It is possible to auto-generate the input fields for a
Views Model properties
 @Html.EditorForModel()
 May have to ignore unwanted Model properties
with [ScaffoldColumn(false)]
Exercise : Scaffolding View
using Model  Change the save form on
the Index View to use
@Html.EditorForModel() and
run
 You should see most of the
properties are provided
with relevant inputs
 To tell the ‘auto-scaffolder’
to ignore certain properties,
give the properties the
[ScaffoldColumn(false)]
attribute
Model Attributes
 Model properties can be given attributes to provide
additional information about them
 This is especially useful in validation
 Attributes include
 [Required]
 Marks the property as non-optional
 [DisplayName]
 Overrides the default label of a property in the view
 [StringLength(50), MinimumLength=3]
 Sets a max length for a string property
 [Range(0,5]
 Provided value must be within a range
ModelState
 Once a Model has been posted back to an
action we can check it’s ‘State’ and whether it is
in a valid state
 Discussed in next slide
Exercise : Model Attributes
for Validation
 Add some validation attributes to the
HomeViewModel
If the Model is Invalid we pass it
back to the calling Action
Continued..
Exercise : Model Attributes
for Validation continued..
 You can alter the Index View to use
@Html.ValidationSummary() which will list all the
errors on the Model
 Else by default validation messages will appear
next to the relevant input controls
@Html.ValidationSummary()
Model property validation
messages
Async Actions in Controllers
 Helps avoid HttpRequests from blocking requests
 Uses new async and await keywords in C#5
 The return type is wrapped in Task<Something>
 Use on long Actions i.e.
 That call external apis
 That do file IO operations
Actions on Controllers calling long running
operations should be asynchronous
Described well here..
http://stackoverflow.com/questions/190875
13/what-is-the-advantage-of-using-async-
with-mvc5
Ad

More Related Content

What's hot (20)

Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend Framework
Juan Antonio
 
Mvc4
Mvc4Mvc4
Mvc4
Muhammad Younis
 
Mvc by asp.net development company in india - part 2
Mvc by asp.net development company in india  - part 2Mvc by asp.net development company in india  - part 2
Mvc by asp.net development company in india - part 2
iFour Institute - Sustainable Learning
 
ASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation ControlsASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation Controls
Randy Connolly
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101
Rich Helton
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
Abhishek Sur
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
Chui-Wen Chiu
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
Barry Gervin
 
jQuery plugins & JSON
jQuery plugins & JSONjQuery plugins & JSON
jQuery plugins & JSON
iFour Institute - Sustainable Learning
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
Divya Sharma
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
SHADAB ALI
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
Jennifer Estrada
 
3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC
Mohd Manzoor Ahmed
 
Creating a custom connector in mule
Creating a custom connector in muleCreating a custom connector in mule
Creating a custom connector in mule
Achyuta Lakshmi
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
ASG
 
Mvc
MvcMvc
Mvc
Furqan Ashraf
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
Volkan Uzun
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Development
joelabrahamsson
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Aaron Schram
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
erdemergin
 
Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend Framework
Juan Antonio
 
ASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation ControlsASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation Controls
Randy Connolly
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101
Rich Helton
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
Abhishek Sur
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
Chui-Wen Chiu
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
Barry Gervin
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
SHADAB ALI
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
Jennifer Estrada
 
3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC
Mohd Manzoor Ahmed
 
Creating a custom connector in mule
Creating a custom connector in muleCreating a custom connector in mule
Creating a custom connector in mule
Achyuta Lakshmi
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
ASG
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
Volkan Uzun
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Development
joelabrahamsson
 

Similar to MVC Training Part 2 (20)

AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
Ran Wahle
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
Ravindra K
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
Mădălin Ștefîrcă
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
vchircu
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnan
Gigin Krishnan
 
Stephen Kennedy Silverlight 3 Deep Dive
Stephen Kennedy Silverlight 3 Deep DiveStephen Kennedy Silverlight 3 Deep Dive
Stephen Kennedy Silverlight 3 Deep Dive
MicrosoftFeed
 
MVC 4
MVC 4MVC 4
MVC 4
Vasilios Kuznos
 
Angular Framework ppt for beginners and advanced
Angular Framework ppt for beginners and advancedAngular Framework ppt for beginners and advanced
Angular Framework ppt for beginners and advanced
Preetha Ganapathi
 
Adding a view
Adding a viewAdding a view
Adding a view
Nhan Do
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
jinaldesailive
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
Akhil Mittal
 
Test
TestTest
Test
guest25229c
 
ASP.MVC Training
ASP.MVC TrainingASP.MVC Training
ASP.MVC Training
Mahesh Sikakolli
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
Volkan Uzun
 
Asp.net mvc training
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc training
icubesystem
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
Sunpawet Somsin
 
Ctools presentation
Ctools presentationCtools presentation
Ctools presentation
Digitaria
 
10 ways to bind multiple models on a view in mvc code project
10 ways to bind multiple models on a view in mvc   code project10 ways to bind multiple models on a view in mvc   code project
10 ways to bind multiple models on a view in mvc code project
Akshat Kumar
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
Ran Wahle
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
Ravindra K
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
vchircu
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnan
Gigin Krishnan
 
Stephen Kennedy Silverlight 3 Deep Dive
Stephen Kennedy Silverlight 3 Deep DiveStephen Kennedy Silverlight 3 Deep Dive
Stephen Kennedy Silverlight 3 Deep Dive
MicrosoftFeed
 
Angular Framework ppt for beginners and advanced
Angular Framework ppt for beginners and advancedAngular Framework ppt for beginners and advanced
Angular Framework ppt for beginners and advanced
Preetha Ganapathi
 
Adding a view
Adding a viewAdding a view
Adding a view
Nhan Do
 
Mvc interview questions – deep dive jinal desai
Mvc interview questions – deep dive   jinal desaiMvc interview questions – deep dive   jinal desai
Mvc interview questions – deep dive jinal desai
jinaldesailive
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
Akhil Mittal
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
Volkan Uzun
 
Asp.net mvc training
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc training
icubesystem
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
Sunpawet Somsin
 
Ctools presentation
Ctools presentationCtools presentation
Ctools presentation
Digitaria
 
10 ways to bind multiple models on a view in mvc code project
10 ways to bind multiple models on a view in mvc   code project10 ways to bind multiple models on a view in mvc   code project
10 ways to bind multiple models on a view in mvc code project
Akshat Kumar
 
Ad

More from Lee Englestone (11)

Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
Lee Englestone
 
Augmented Reality On iOS With ARKit Xamarin and C#
Augmented Reality On iOS With ARKit Xamarin and C#Augmented Reality On iOS With ARKit Xamarin and C#
Augmented Reality On iOS With ARKit Xamarin and C#
Lee Englestone
 
Reinventing Education Hackathon - LeARn
Reinventing Education Hackathon - LeARnReinventing Education Hackathon - LeARn
Reinventing Education Hackathon - LeARn
Lee Englestone
 
.NET Foundation website suggestions for improvement
.NET Foundation website suggestions for improvement.NET Foundation website suggestions for improvement
.NET Foundation website suggestions for improvement
Lee Englestone
 
25 Tips for Visual Studio
25 Tips for Visual Studio25 Tips for Visual Studio
25 Tips for Visual Studio
Lee Englestone
 
Tweet From Every Country Barcamp Manchester
Tweet From Every Country Barcamp ManchesterTweet From Every Country Barcamp Manchester
Tweet From Every Country Barcamp Manchester
Lee Englestone
 
Organisational Learning
Organisational LearningOrganisational Learning
Organisational Learning
Lee Englestone
 
Lincoln Hack 2018
Lincoln Hack 2018Lincoln Hack 2018
Lincoln Hack 2018
Lee Englestone
 
Familee bootstrapped-biz
Familee bootstrapped-bizFamilee bootstrapped-biz
Familee bootstrapped-biz
Lee Englestone
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
Lee Englestone
 
Visual Studio 2010 and ASP.Net 4
Visual Studio 2010 and ASP.Net 4Visual Studio 2010 and ASP.Net 4
Visual Studio 2010 and ASP.Net 4
Lee Englestone
 
Augmented Reality On iOS With ARKit Xamarin and C#
Augmented Reality On iOS With ARKit Xamarin and C#Augmented Reality On iOS With ARKit Xamarin and C#
Augmented Reality On iOS With ARKit Xamarin and C#
Lee Englestone
 
Reinventing Education Hackathon - LeARn
Reinventing Education Hackathon - LeARnReinventing Education Hackathon - LeARn
Reinventing Education Hackathon - LeARn
Lee Englestone
 
.NET Foundation website suggestions for improvement
.NET Foundation website suggestions for improvement.NET Foundation website suggestions for improvement
.NET Foundation website suggestions for improvement
Lee Englestone
 
25 Tips for Visual Studio
25 Tips for Visual Studio25 Tips for Visual Studio
25 Tips for Visual Studio
Lee Englestone
 
Tweet From Every Country Barcamp Manchester
Tweet From Every Country Barcamp ManchesterTweet From Every Country Barcamp Manchester
Tweet From Every Country Barcamp Manchester
Lee Englestone
 
Organisational Learning
Organisational LearningOrganisational Learning
Organisational Learning
Lee Englestone
 
Familee bootstrapped-biz
Familee bootstrapped-bizFamilee bootstrapped-biz
Familee bootstrapped-biz
Lee Englestone
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
Lee Englestone
 
Visual Studio 2010 and ASP.Net 4
Visual Studio 2010 and ASP.Net 4Visual Studio 2010 and ASP.Net 4
Visual Studio 2010 and ASP.Net 4
Lee Englestone
 
Ad

Recently uploaded (20)

Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 

MVC Training Part 2

  • 1. ASP.NET MVC Training – Part 2 AN ASP.NET MVC INTRODUCTION Lee Englestone (@LeeEnglestone) Tech Lead @ Kitbag.com www.ManchesterDeveloper.com
  • 2. Areas  Areas group related Models, Views and Controllers  By default no Areas exists  They appear in the route like so  http://www.website.com/{Area}/{Controller}/{Action}/{Id}  You can try adding an Area to your application and you’ll see it creates a new folder and sub-folders for Models, Views and Controllers and the code to register the Area itself  We don’t use Areas
  • 3. HtmlHelpers  HtmlHelpers are methods that can be executed within Razor views to generate HTML  They are actually just extension methods and therefore you can write your own HtmlHelper methods  The @Html.Action Helper method can be used to generate links given controller, actions names and id values  We’ve already encountered @Html.LabelFor() and @Html.TextBoxFor() in Part 1
  • 4. Partial Views  A view that can be rendered in another view  Conceptually similar to WebForms UserControls  By convention located in the Views/Shared folder  By convention prefixed with an underscore  Can be returned from Controller Actions with a Model Next we’ll create a partial view that returns a picture of a cat
  • 5. Exercise : Create and use a simple Partial View  Create a new PartialView at Views/Shared/_FunnyCat.cshtml  Put an image of a funny cat in /Images  Update _FunnyCat.cshtml  Add @Html.Partial(“FunnyCat”, “Steve”) to Index.html  Run
  • 6. Custom Mobile Views using DisplayModes  Rules can be put into place to serve different views with different extensions in different circumstances  A popular method is that if a user has requested a page on a mobile device and there are 2 versions of a View in the View folder  Index.cshtml  Index.mobile.cshtml  Then the relevant view will be returned  There is a built in DisplayMode for *.mobile.cshtml views
  • 7. Exercise : Create Mobile View  Create a new View called ViewsIndex.mobile.cshtml  Make it obvious it is the Mobile View  Run the application and emulate a Mobile device
  • 8. CSS Boostrap Framework  Bootstrap is a popular CSS and JavaScript framework that now is included in / used by new ASP.NET MVC Application projects  http://getbootstrap.com/  It warrants a training course in itself (so check it out) but some of main things it gives are  Browser reset  Grid system  Glyphicons  Popovers, tooltips, tabs, modals, pagination
  • 9. Dependency Injection  A way of objecting dependencies  Generally speaking we use Constructor Injection Constructor Injection
  • 10. Exercise : Dependency Injection  Add Ninject to MVC Application using NuGet  Creates App_Start/NinjectWebCommon.cs Mappings can be put here in the format kernel.Bind<ISomeInterface>().To(SomeClass);
  • 11. TDD/Unit Testing  Controllers can be easily Unit Tested  Can mock dependencies  A few things you could Unit Test  The View (or result) returned from an Action is of the correct type  The Model returned from an Action is correct
  • 12. Exercise : Unit Testing Controllers  Create a new ClassLibrary called Tests and Reference NUnit using NuGet  Add a reference in the class library to the Web Application  Create a new File called HomeControllerTests.cs  Assert that the Type of Model returned from the Index View on the controller is HomeViewModel
  • 13. Bundling  The merging together and serving of multiple files  Instead of a request for each javascript/css file, files are ‘merged together’ to reduce number of requests  Bundles defined in App_Start/BundleConfig.cs  Can be turned off whilst debugging / working locally
  • 15. Minification  The removing of whitespace in served javascript and css files  Is done automatically to styles and scripts in a Bundle  Can be turned off whilst debugging / working locally
  • 16. Scaffolding Views  It is possible to auto-generate the input fields for a Views Model properties  @Html.EditorForModel()  May have to ignore unwanted Model properties with [ScaffoldColumn(false)]
  • 17. Exercise : Scaffolding View using Model  Change the save form on the Index View to use @Html.EditorForModel() and run  You should see most of the properties are provided with relevant inputs  To tell the ‘auto-scaffolder’ to ignore certain properties, give the properties the [ScaffoldColumn(false)] attribute
  • 18. Model Attributes  Model properties can be given attributes to provide additional information about them  This is especially useful in validation  Attributes include  [Required]  Marks the property as non-optional  [DisplayName]  Overrides the default label of a property in the view  [StringLength(50), MinimumLength=3]  Sets a max length for a string property  [Range(0,5]  Provided value must be within a range
  • 19. ModelState  Once a Model has been posted back to an action we can check it’s ‘State’ and whether it is in a valid state  Discussed in next slide
  • 20. Exercise : Model Attributes for Validation  Add some validation attributes to the HomeViewModel If the Model is Invalid we pass it back to the calling Action Continued..
  • 21. Exercise : Model Attributes for Validation continued..  You can alter the Index View to use @Html.ValidationSummary() which will list all the errors on the Model  Else by default validation messages will appear next to the relevant input controls @Html.ValidationSummary() Model property validation messages
  • 22. Async Actions in Controllers  Helps avoid HttpRequests from blocking requests  Uses new async and await keywords in C#5  The return type is wrapped in Task<Something>  Use on long Actions i.e.  That call external apis  That do file IO operations Actions on Controllers calling long running operations should be asynchronous Described well here.. http://stackoverflow.com/questions/190875 13/what-is-the-advantage-of-using-async- with-mvc5