![](/img/trans.png)
[英]How pass objects from one page to another on ASP.Net Core with razor pages?
[英]Is there any easy way to to pass complex objects from one PageModel file to another in asp.net core razor pages (mvvm, not mvc)?
我熟悉asp.net mvc开发。 在该框架中,传递复杂对象(例如对象列表)就像在一个控制器中创建公共静态列表一样简单:
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}
}
并使用以下代码在另一个控制器中引用: ControllerName.lstProducts
我正在 asp.net 核心剃刀页面中构建一个应用程序(使用带有 PageModel 代码隐藏文件而不是 MVC 的剃刀页面)并且从一个 PageModel 文件传递一个复杂的对象一点也不简单。 我觉得这个问题的答案应该是显而易见的,但我仍然在挠头。
如果您希望从控制器传递的对象进行查看,请使用 viewbag。
ViewBag.ListProducts = lstProducts;
请注意,此 Viewbag 只能使用您的 PageMdel 在强类型视图中访问。
如果您希望此对象从第一个请求传递到第二个请求,请使用 tempdata。
TempData[“ListProducts”]= lstProducts;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.