In the Views/Shared folder, I had my Grid. cshtml
In the Controllers folder, I had my GridController. cs
To show a grid, in the View I added:
1 | @Html. RenderAction("Grid", "Grid", new {gridId=X, dataId=Y, param=Z, etc }) |
The grid had async loading and paging, so in the GridController, I had:
1 2 3 4 5 | public ActionResult Grid(int gridId, int dataId, etc) { <blah, blah>; return PartialView(myModel); } |
and
1 2 3 4 5 | public ActionResult Read(int dataId, int PageNo) { <blah, blah>; return Json(data, JsonRequestBehavior. AllowGet); } |
So, moving to asp. net core, goodbye child Actions, hello ViewComponents. I have successfully created the ViewComponent class and the view and I am able to show the initial state of the Grid in the hosting View page. Still, I need to find a way to call the Read method and load data into my Grid. . .
Alas! As I found out after a lot of googling:
A view component never directly handles an HTTP request so you can’t call directly to a view component from the client side. You will need to wrap the view component with a controller if your application requires this behaviour. "
So, should I create a GridController. cs as well? Is this the best way to go, or there exists some other way / best practice?
Thanks in advance whoever takes the time to respond.