Saturday, November 3, 2018

Asp.Net MVC Tutorials About Views

Asp.Net MVC Tutorials about views. Views are stored in views folder with the same name as the controller in the controller folder. Every View derived from WebViewPage Class in System.Web.Mvc namespace. MVC supports the Razor View Engine with the extension of .cshtml. Views are used to display the data from the model with help of controller. The controller takes the income HTTP request and renders the specified View with data to the browser.

Asp.Net MVC Views

How to create Views in Asp.Net MVC. Open Visual Studio click on File --> New --> Projects. and give the name as all tech geeks.

Asp.Net MVC Views all tech geeks

Next, select the Empty option from top pan and click MVC checkbox, and click ok Button.

Asp.Net MVC Views all tech geeks

You get the application structure and as shown below image and right click on the controller add controller name.
Asp.Net MVC Views all tech geeks
with views in views folder and no classes in controllers
Asp.Net MVC Views all tech geeks
Right click on Controller

Asp.Net MVC Views all tech geeks
Give the name to the controller

Finally, the controller is created and also a view folder in created in the view folder as sown below.

Asp.Net MVC Views all tech geeks

Now Add the view for controller right-click on action result Index. give the name same as action result name to view also. MVC view

Now .chhtml file will be generated and run the .cshtml file find out pt in the browser. MVC view
Index.cshtml file MVC view
This is the output MVC view MVC uses the Razor view engine and generates the .cshtml files. Razor view means combining the Server side code (C# code) with HTML code. here we are using the @ character at server side code. in we are using <% %>. but in MVC @ character reduces the time to develop the application.

Example code for Razor

    ViewBag.Title = "Index";

<h2>Welcome to my first All Tech Geeks Views Part</h2>

                                               Asp.Net MVC  - Get Started

  1. MVC Tutorials- Get Started 
  2. Architecture
  3. First Application
  4. Folder Structure
  5. Controller
  7. Model
  8. Bundling
  9. View Bag
  10. Temp Data
  11. View Data
  12. Action Methods
  13. Action Selectors
  14. HTML Helpers
  15. Partial Views
  16. Layout View
  17. Filters
  18. Action Filters
  19. Validations
  20. Area
  21. What is Entity Framework and types  
  22. Creating Project in Database First Approach
  23. Creating Project in Code first approach
  24. Creating Project in Model Base First approach

No comments: