asp.net mvc views
DESCRIPTION
TRANSCRIPT
![Page 2: ASP.NET MVC Views](https://reader036.vdocuments.us/reader036/viewer/2022082804/5491ecaeb479591a7b8b465e/html5/thumbnails/2.jpg)
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.
![Page 3: ASP.NET MVC Views](https://reader036.vdocuments.us/reader036/viewer/2022082804/5491ecaeb479591a7b8b465e/html5/thumbnails/3.jpg)
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
![Page 4: ASP.NET MVC Views](https://reader036.vdocuments.us/reader036/viewer/2022082804/5491ecaeb479591a7b8b465e/html5/thumbnails/4.jpg)
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.
![Page 6: ASP.NET MVC Views](https://reader036.vdocuments.us/reader036/viewer/2022082804/5491ecaeb479591a7b8b465e/html5/thumbnails/6.jpg)
Passing Data from Controller to Views
Data can be passed from controllers to views using three different ways
1. ViewBag
2. ViewData
3. TempData
![Page 7: ASP.NET MVC Views](https://reader036.vdocuments.us/reader036/viewer/2022082804/5491ecaeb479591a7b8b465e/html5/thumbnails/7.jpg)
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.
![Page 8: ASP.NET MVC Views](https://reader036.vdocuments.us/reader036/viewer/2022082804/5491ecaeb479591a7b8b465e/html5/thumbnails/8.jpg)
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.
![Page 9: ASP.NET MVC Views](https://reader036.vdocuments.us/reader036/viewer/2022082804/5491ecaeb479591a7b8b465e/html5/thumbnails/9.jpg)
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
![Page 10: ASP.NET MVC Views](https://reader036.vdocuments.us/reader036/viewer/2022082804/5491ecaeb479591a7b8b465e/html5/thumbnails/10.jpg)
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
![Page 11: ASP.NET MVC Views](https://reader036.vdocuments.us/reader036/viewer/2022082804/5491ecaeb479591a7b8b465e/html5/thumbnails/11.jpg)
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.