A view component/controller is created as a controller inheriting from the Controller class. It can be a hybrid object if:
- It's decorated by the ViewComponent attribute with a ViewComponent name as parameter:
[ViewComponent(Name = "BasketComponent")] public class ProductController : Controller
- It contains an Invoke() method that returns an IViewComponentResult. The ViewData property of the ViewViewComponent object returned is the name of the .cshtml view component:
public IViewComponentResult Invoke() { List<string> listeData = new List<string>(); return new ViewViewComponentResult() { ViewName = "BasketData", ViewData = new ViewDataDictionary<IEnumerable<string>> (ViewData, listeData) }; }
When it is invoked, the searched ...