Tutorial by Examples

View components encapsulate reusable pieces of logic and views. They are defined by: A ViewComponent class containing the logic for fetching and preparing the data for the view and deciding which view to render. One or more views Since they contain logic, they are more flexible than partial v...
The default project template creates a partial view _LoginPartial.cshtml which contains a bit of logic for finding out whether the user is logged in or not and find out its user name. Since a view component might be a better fit (as there is logic involved and even 2 services injected) the followin...
When inheriting from base Controller class provided by the framework, you can use the convenience method ViewComponent() to return a view component from the action: public IActionResult GetMyComponent() { return ViewComponent("Login", new { param1 = "foo", param2 = 42 }); ...

Page 1 of 1