0
votes

I am familiar with asp.net mvc development. In that framework passing complex objects (such as a list of objects) was as simple as creating the public static list in one controller:

public static List<T_Material> lstProducts = new List<T_Material>()
        {
            new T_Material {T_MaterialID = 1, Name = "Product1", Description="Description1", Price=20, MonthsOfAccess=20},
            new T_Material {T_MaterialID = 2, Name = "Product2", Description="Description2", Price=20, MonthsOfAccess=20}
        }

and referencing in another controller with the following code: ControllerName.lstProducts

I am building an application in asp.net core razor pages (using razor pages with a PageModel code behind file not MVC) and passing a complex object from one PageModel file is not simple at all. I feel like the answer to this should be obvious but I am still scratching my head.

1

1 Answers

0
votes

If you want the object passed from controller to view then use viewbag.

ViewBag.ListProducts = lstProducts;

Note this Viewbag can only be access in strongly typed view using your PageMdel.

If you want this object to be passed from first request to second request, then use tempdata.

TempData[“ListProducts”]= lstPrroducts;