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

More Related Content

What's hot

Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend Framework
Juan Antonio
 
Mvc4
Mvc4Mvc4
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
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
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
 

What's hot (20)

Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend Framework
 
Mvc4
Mvc4Mvc4
Mvc4
 
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
 
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
 
Entity frameworks101
Entity frameworks101Entity frameworks101
Entity frameworks101
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
 
jQuery plugins & JSON
jQuery plugins & JSONjQuery plugins & JSON
jQuery plugins & JSON
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 
Introduction to asp.net
Introduction to asp.netIntroduction to asp.net
Introduction to asp.net
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
 
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
 
Creating a custom connector in mule
Creating a custom connector in muleCreating a custom connector in mule
Creating a custom connector in mule
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
 
Mvc
MvcMvc
Mvc
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Development
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 

Similar to MVC Training Part 2

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
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
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
 

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
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by 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
 
MVC 4
MVC 4MVC 4
MVC 4
 
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
 
Adding a view
Adding a viewAdding a view
Adding a view
 
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
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
Test
TestTest
Test
 
ASP.MVC Training
ASP.MVC TrainingASP.MVC Training
ASP.MVC Training
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
 
Asp.net mvc training
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc training
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Ctools presentation
Ctools presentationCtools presentation
Ctools presentation
 
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
 

More from Lee Englestone

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
 

More from Lee Englestone (11)

Introduction to C#
Introduction to C#Introduction to C#
Introduction to 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#
Augmented Reality On iOS With ARKit Xamarin and C#
 
Reinventing Education Hackathon - LeARn
Reinventing Education Hackathon - LeARnReinventing Education Hackathon - LeARn
Reinventing Education Hackathon - LeARn
 
.NET Foundation website suggestions for improvement
.NET Foundation website suggestions for improvement.NET Foundation website suggestions for improvement
.NET Foundation website suggestions for improvement
 
25 Tips for Visual Studio
25 Tips for Visual Studio25 Tips for Visual Studio
25 Tips for Visual Studio
 
Tweet From Every Country Barcamp Manchester
Tweet From Every Country Barcamp ManchesterTweet From Every Country Barcamp Manchester
Tweet From Every Country Barcamp Manchester
 
Organisational Learning
Organisational LearningOrganisational Learning
Organisational Learning
 
Lincoln Hack 2018
Lincoln Hack 2018Lincoln Hack 2018
Lincoln Hack 2018
 
Familee bootstrapped-biz
Familee bootstrapped-bizFamilee bootstrapped-biz
Familee bootstrapped-biz
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
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
 

Recently uploaded

IoT In Manufacturing_ Use Cases, Benefits, and Challenges.pdf
IoT In Manufacturing_ Use Cases, Benefits, and Challenges.pdfIoT In Manufacturing_ Use Cases, Benefits, and Challenges.pdf
IoT In Manufacturing_ Use Cases, Benefits, and Challenges.pdf
mohitd6
 
Busty Girls Call Mumbai 9930245274 Unlimited Short Providing Girls Service Av...
Busty Girls Call Mumbai 9930245274 Unlimited Short Providing Girls Service Av...Busty Girls Call Mumbai 9930245274 Unlimited Short Providing Girls Service Av...
Busty Girls Call Mumbai 9930245274 Unlimited Short Providing Girls Service Av...
revolutionary575
 
Vip Girls Call ServiCe Hyderabad 0000000000 Pooja Best High Class Hyderabad A...
Vip Girls Call ServiCe Hyderabad 0000000000 Pooja Best High Class Hyderabad A...Vip Girls Call ServiCe Hyderabad 0000000000 Pooja Best High Class Hyderabad A...
Vip Girls Call ServiCe Hyderabad 0000000000 Pooja Best High Class Hyderabad A...
ashiklo9823
 
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
neshakor5152
 
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
josephinedrea942
 
Prada Group Reports Strong Growth in First Quarter …
Prada Group Reports Strong Growth in First Quarter …Prada Group Reports Strong Growth in First Quarter …
Prada Group Reports Strong Growth in First Quarter …
908dutch
 
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
902basic
 
Authentication Review-June -2024 AP & TS.pptx
Authentication Review-June -2024 AP & TS.pptxAuthentication Review-June -2024 AP & TS.pptx
Authentication Review-June -2024 AP & TS.pptx
DEMONDUOS
 
UMiami degree offer diploma Transcript
UMiami degree offer diploma TranscriptUMiami degree offer diploma Transcript
UMiami degree offer diploma Transcript
attueb
 
當測試開始左移
當測試開始左移當測試開始左移
當測試開始左移
Jersey (CHE-PING) Su
 
Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech.Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech
 
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptxWired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
SimonedeGijt
 
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
dream girl
 
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdfAI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
Daniel Zivkovic
 
Odoo E-commerce website development guides
Odoo E-commerce website development guidesOdoo E-commerce website development guides
Odoo E-commerce website development guides
jhkdigitalmarketing
 
Artificial intelligence in customer services or chatbots
Artificial intelligence  in customer services or chatbotsArtificial intelligence  in customer services or chatbots
Artificial intelligence in customer services or chatbots
kayash1656
 
ThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and DjangoThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and Django
akshesh doshi
 
Top Chinese Government-backed APT Groups
Top Chinese Government-backed APT GroupsTop Chinese Government-backed APT Groups
Top Chinese Government-backed APT Groups
SOCRadar
 
Il Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazioneIl Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazione
confluent
 
bangalore Girls call 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
bangalore Girls call  👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Deliverybangalore Girls call  👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
bangalore Girls call 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
sunilverma7884
 

Recently uploaded (20)

IoT In Manufacturing_ Use Cases, Benefits, and Challenges.pdf
IoT In Manufacturing_ Use Cases, Benefits, and Challenges.pdfIoT In Manufacturing_ Use Cases, Benefits, and Challenges.pdf
IoT In Manufacturing_ Use Cases, Benefits, and Challenges.pdf
 
Busty Girls Call Mumbai 9930245274 Unlimited Short Providing Girls Service Av...
Busty Girls Call Mumbai 9930245274 Unlimited Short Providing Girls Service Av...Busty Girls Call Mumbai 9930245274 Unlimited Short Providing Girls Service Av...
Busty Girls Call Mumbai 9930245274 Unlimited Short Providing Girls Service Av...
 
Vip Girls Call ServiCe Hyderabad 0000000000 Pooja Best High Class Hyderabad A...
Vip Girls Call ServiCe Hyderabad 0000000000 Pooja Best High Class Hyderabad A...Vip Girls Call ServiCe Hyderabad 0000000000 Pooja Best High Class Hyderabad A...
Vip Girls Call ServiCe Hyderabad 0000000000 Pooja Best High Class Hyderabad A...
 
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
 
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
 
Prada Group Reports Strong Growth in First Quarter …
Prada Group Reports Strong Growth in First Quarter …Prada Group Reports Strong Growth in First Quarter …
Prada Group Reports Strong Growth in First Quarter …
 
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
Private Girls Call Navi Mumbai 🛵🚡9820252231 💃 Choose Best And Top Girl Servic...
 
Authentication Review-June -2024 AP & TS.pptx
Authentication Review-June -2024 AP & TS.pptxAuthentication Review-June -2024 AP & TS.pptx
Authentication Review-June -2024 AP & TS.pptx
 
UMiami degree offer diploma Transcript
UMiami degree offer diploma TranscriptUMiami degree offer diploma Transcript
UMiami degree offer diploma Transcript
 
當測試開始左移
當測試開始左移當測試開始左移
當測試開始左移
 
Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech.Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech.
 
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptxWired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
 
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
Russian Girls Call Mumbai 🛵🚡9833363713 💃 Choose Best And Top Girl Service And...
 
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdfAI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
AI - Your Startup Sidekick (Leveraging AI to Bootstrap a Lean Startup).pdf
 
Odoo E-commerce website development guides
Odoo E-commerce website development guidesOdoo E-commerce website development guides
Odoo E-commerce website development guides
 
Artificial intelligence in customer services or chatbots
Artificial intelligence  in customer services or chatbotsArtificial intelligence  in customer services or chatbots
Artificial intelligence in customer services or chatbots
 
ThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and DjangoThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and Django
 
Top Chinese Government-backed APT Groups
Top Chinese Government-backed APT GroupsTop Chinese Government-backed APT Groups
Top Chinese Government-backed APT Groups
 
Il Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazioneIl Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazione
 
bangalore Girls call 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
bangalore Girls call  👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Deliverybangalore Girls call  👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
bangalore Girls call 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
 

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