From the course: Learning ASP.NET Core: MVC, Razor Pages, Web APIs & Other Foundations
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Rendering MVC views
From the course: Learning ASP.NET Core: MVC, Razor Pages, Web APIs & Other Foundations
Rendering MVC views
- [Instructor] Views in MVC apps use the same razor syntax as views in razor pages apps. However, because of the separation of concerns in an MVC app, the controller must specifically select the view to use for a given request rather than it being addressed directly the way pages are in razor pages apps. Selecting and returning a view is the last thing I need to add to the current project's action method here on the EngineeringController. The call to the view method on line 11 above isn't past any parameters. Therefore, ASP.NET Core will attempt to locate a view named Index.cshtml and the view will not be passed any model data. For the current project's view, I will also let ASP.NET Core look for a view with the same name as the action method, but I want it to be able to use the EngineeringDepartment instance as its view model. I do that by using the method overload that takes a single model object as a parameter. As I've already mentioned, there's also an overload that allows you to…