dotnettutorials.net/lesson/views-asp-net-core-mvc/
1 Users
0 Comments
15 Highlights
0 Notes
Tags
Top Highlights
View is the component that contains logic to represent the model data (the model data provided to it by a controller) as a user interface with which the end-user can interac
“.cshtml”
The Views in ASP.NET Core MVC Application are generally returned from the Controller Action Method. We use the ViewResult return type to return a view from an action method.
four overload versions of the View()
If you are using the View() or View(object model) extension method to return a view, then it will look for the view file with the same name as the action method name.
need to use the overloaded version of the View method which takes the object model as an input parameter else you can simply use the View() extension method which does not take any parameter
If you want to return a view from an action method whose name is different than the action method name then you need to use either View(string viewName) or View(string viewName, object model) Extension Methods.
When you are using an absolute path, in order to get to the project’s root directory, you can use / or ~/.
separation of concerns (codes)
It separates the user interface from the business logic or you can say from the rest of the application.
uses the Razor syntax which makes it easy to switch between the HTML markup and C# code.
In ASP.NET Core MVC Web Application, when an action method of a controller returns a view, a process called view discovery takes place.
How Does the Controller Action Method Identify the View in ASP.NET Core MVC?
determines which view file should be used based on the view name.
So, it doesn’t matter if you implicitly return the ViewResult with return View(); or explicitly pass the view name to the View method with return View(“<ViewName>”);. In both cases, view discovery searches for a matching view file in this order: Views/[ControllerName]/[ViewName].cshtml Views/Shared/[ViewName].cshtml
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.