SlideShare a Scribd company logo
1 of 11
ASP.NET MVC(Views)

mahmoodfcis@gmail.com
Views
 Views are the UI layer of the MVC application.
 They are not responsible for any logic
 Views are placed inside the Views folder of the ASP.NET MVC application
 There is a folder for each controller inside the Views folder
 Razor views have .cshtml, .vbhtml while web forms have .aspx, .asp extensions.

mahmoodfcis@gmail.com
ASP.NET MVC View Engines
View Engines are responsible for rendering the HTML from your views to the browser. The view engine template will have

different syntax for implementation. Currently there are few number of view engines available for MVC and the top four
view engines are Razor, traditional ASPX, Spark and Nhaml.
 Razor is the best view engine. Uses @ for rendering HTML
 Web forms engine uses <%%>
 See the other view engines doc at
http://www.codeproject.com/Articles/467850/ASP-NET-MVC-view-engines
http://channel9.msdn.com/coding4fun/articles/Developer-Review-Four-ASPNET-MVC-View-Engines

mahmoodfcis@gmail.com
Binding Models to Views
 The controller is responsible for binding the model data to the view.
 @model is used to bind the model to a view.
 Views that are bound to models are called strongly typed views.

mahmoodfcis@gmail.com
HTML Helpers

mahmoodfcis@gmail.com
Passing Data from Controller to Views
Data can be passed from controllers to views using three different ways
1. ViewBag
2. ViewData
3. TempData

mahmoodfcis@gmail.com
Partial Views
They are similar to user controls in asp.net web forms.
Html.RenderPartial and @Html.Partial are used to include
The partial views inside a view.

mahmoodfcis@gmail.com
HTTP Post and GET Action selectors
HttpGet and HttpPost are used for actions that read and submit data from views to controllers
For example adding data in a view then submitting them back to the controller action.

mahmoodfcis@gmail.com
Localization
 Localization in ASP.NET MVC is similar to ASP.NET web forms.
 Tips for implementing localization in an asp.net MVC application

1.

Use Resource files (.resx)

2.

Place resource files in a folder out of the global resource folders of the ASP.NET

3.

Chance the access modifier of the resource to public

4.

Avoid writing hard coded texts.

5.

Use ErrorMessageResourceType, ResourceType data annotations in the fields of the model

6.

Design different stylessheets for the different languages

7.

Switch between languages in the global.asax file

mahmoodfcis@gmail.com
Bundling
Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You
can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page
load performance.
You can add your bundles in the BundleConfig class.
Bundling is disabled in the Debug mode so to enable bundling you must set the Debug=“False” in the web.config

mahmoodfcis@gmail.com
Minification
Minification performs a variety of different code optimizations to scripts or css, such as removing unnecessary white space
and comments and shortening variable names to one character. Consider the following JavaScript function.

mahmoodfcis@gmail.com

More Related Content

More from Mahmoud Tolba

Developing cross platforms mobile applications using the Apache Cordova
Developing cross platforms mobile applications using the Apache CordovaDeveloping cross platforms mobile applications using the Apache Cordova
Developing cross platforms mobile applications using the Apache CordovaMahmoud Tolba
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity FrameworkMahmoud Tolba
 
Windows Communication Foundation
Windows Communication FoundationWindows Communication Foundation
Windows Communication FoundationMahmoud Tolba
 
ASP.NET MVC controllers
ASP.NET MVC controllersASP.NET MVC controllers
ASP.NET MVC controllersMahmoud Tolba
 
ASP.NET MVC4 Overview
ASP.NET MVC4 OverviewASP.NET MVC4 Overview
ASP.NET MVC4 OverviewMahmoud Tolba
 
Top emerging technologies
Top emerging technologiesTop emerging technologies
Top emerging technologiesMahmoud Tolba
 

More from Mahmoud Tolba (8)

Developing cross platforms mobile applications using the Apache Cordova
Developing cross platforms mobile applications using the Apache CordovaDeveloping cross platforms mobile applications using the Apache Cordova
Developing cross platforms mobile applications using the Apache Cordova
 
JQuery Overview
JQuery OverviewJQuery Overview
JQuery Overview
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
 
Windows Communication Foundation
Windows Communication FoundationWindows Communication Foundation
Windows Communication Foundation
 
ASP.NET MVC controllers
ASP.NET MVC controllersASP.NET MVC controllers
ASP.NET MVC controllers
 
ASP.NET MVC4 Overview
ASP.NET MVC4 OverviewASP.NET MVC4 Overview
ASP.NET MVC4 Overview
 
Top emerging technologies
Top emerging technologiesTop emerging technologies
Top emerging technologies
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 

Recently uploaded

The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 

Recently uploaded (20)

The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 

ASP.NET MVC Views

  • 2. Views  Views are the UI layer of the MVC application.  They are not responsible for any logic  Views are placed inside the Views folder of the ASP.NET MVC application  There is a folder for each controller inside the Views folder  Razor views have .cshtml, .vbhtml while web forms have .aspx, .asp extensions. mahmoodfcis@gmail.com
  • 3. ASP.NET MVC View Engines View Engines are responsible for rendering the HTML from your views to the browser. The view engine template will have different syntax for implementation. Currently there are few number of view engines available for MVC and the top four view engines are Razor, traditional ASPX, Spark and Nhaml.  Razor is the best view engine. Uses @ for rendering HTML  Web forms engine uses <%%>  See the other view engines doc at http://www.codeproject.com/Articles/467850/ASP-NET-MVC-view-engines http://channel9.msdn.com/coding4fun/articles/Developer-Review-Four-ASPNET-MVC-View-Engines mahmoodfcis@gmail.com
  • 4. Binding Models to Views  The controller is responsible for binding the model data to the view.  @model is used to bind the model to a view.  Views that are bound to models are called strongly typed views. mahmoodfcis@gmail.com
  • 6. Passing Data from Controller to Views Data can be passed from controllers to views using three different ways 1. ViewBag 2. ViewData 3. TempData mahmoodfcis@gmail.com
  • 7. Partial Views They are similar to user controls in asp.net web forms. Html.RenderPartial and @Html.Partial are used to include The partial views inside a view. mahmoodfcis@gmail.com
  • 8. HTTP Post and GET Action selectors HttpGet and HttpPost are used for actions that read and submit data from views to controllers For example adding data in a view then submitting them back to the controller action. mahmoodfcis@gmail.com
  • 9. Localization  Localization in ASP.NET MVC is similar to ASP.NET web forms.  Tips for implementing localization in an asp.net MVC application 1. Use Resource files (.resx) 2. Place resource files in a folder out of the global resource folders of the ASP.NET 3. Chance the access modifier of the resource to public 4. Avoid writing hard coded texts. 5. Use ErrorMessageResourceType, ResourceType data annotations in the fields of the model 6. Design different stylessheets for the different languages 7. Switch between languages in the global.asax file mahmoodfcis@gmail.com
  • 10. Bundling Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page load performance. You can add your bundles in the BundleConfig class. Bundling is disabled in the Debug mode so to enable bundling you must set the Debug=“False” in the web.config mahmoodfcis@gmail.com
  • 11. Minification Minification performs a variety of different code optimizations to scripts or css, such as removing unnecessary white space and comments and shortening variable names to one character. Consider the following JavaScript function. mahmoodfcis@gmail.com

Editor's Notes

  1. http://httputility.com/various/razorhelperscheatsheet.html