I was wondering if it was possible to use ValueTuples as your Razor model. This turned out to work perfectly!
Here is my ViewComponent method(notice that this also works in Razor pages and MVC controllers):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProductListViewComponent : ViewComponent | |
{ | |
public async Task<IViewComponentResult> InvokeAsync() | |
{ | |
var user=new User(); | |
var products=new List<Product>(); | |
return View((user, products)); | |
} | |
} |
And here is my Razor view:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model (Domain.User User, List<Domain.Product> Products) | |
<div class="userinfo-field"><label>Welcome @Model.User.Name</label></div> |