I want to pass multiple parameters to a view component in ASP.NET MVC using C#.
So I did this:
public IViewComponentResult Invoke(Ordering ordering, InvokeRequest invokeRequest)
{
var productList = _context.GetProductForSiteService
.Execute(invokeRequest.ordering, invokeRequest.Searchkey, invokeRequest.page, invokeRequest.pageSize, null).Data;
return View(viewName: "GetProducts", productList);
}
public class InvokeRequest
{
public Ordering ordering { get; set; }
public string Searchkey { get; set; }
public int page { get; set; } = 1;
public int pageSize { get; set; } = 20;
}
and in the view, I have:
@await Component.InvokeAsync("GetProducts", new { Ordering=Ordering.NotOrder, Searchkey="", page=1, pageSize=20 })
but the value of the InvokeRequest in Invoke method is always null, how can I pass multiple parameter to a ViewComponent?