简体   繁体   English

从另一个asp.net页访问列表对象

[英]Accessing list objects from another asp.net page

I create a list ... 我创建一个列表...

private static List<int[]> arrayList = new List<int[]>();

public static void Add(int Id, int Quantity)
{
    int[] buying = new int[] {Id, Quantity};
    arrayList.Add(buying);
}

Now ideally I want to access these list objects from another page, but its the first time I've really used lists and arrays so I don't know where to start? 现在,理想情况下,我想从另一个页面访问这些列表对象,但这是我第一次真正使用列表和数组,因此我不知道从哪里开始?

any pointers? 有指针吗?

Thanks 谢谢

Save the objects's state from one page in Session: 从会话的一页中保存对象的状态:

Session["arrayList"] = arrayList

Access it in another Page: 在另一个页面中访问它:

if(Session["arrayList"]!=null)
 List<int[]> arrayList = Session["arrayList"] as List<int[]>;

1) Your List is private. 1)您的清单是私人的。 U must do it public 2) Where is this code located? U必须将其公开2)此代码位于何处?

You can expose another method like so 您可以公开这样的另一种方法

public static IEnumerable<int> MyArrayList()
{
     return arrayList;
}

This way you can only read the elements in the next page. 这样,您只能阅读下一页中的元素。 If you want to add any elements then you can use your Add() method. 如果要添加任何元素,则可以使用Add()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#asp.net从另一个列表创建字符串列表,该列表返回类对象的列表 - C# asp.net create string list from a another list which returns list of class objects 从ASP.NET中另一个页面的链接按钮访问复选框的属性 - Accessing Properties of checkbox from link button of another page in ASP.NET 从Javascript访问在ASP.NET中创建的对象/行 - Accessing objects/rows created in ASP.NET from Javascript 如何使用剃刀页面在 ASP.Net Core 上将对象从一个页面传递到另一个页面? - How pass objects from one page to another on ASP.Net Core with razor pages? ASP.NET Core:从解决方案中的另一个项目访问appsettings - ASP.NET Core: Accessing appsettings from another project in solution 从ASP.net中的另一个文件夹访问母版页 - Accessing Masterpage from another folder in ASP.net Asp.Net,从上一页访问变量是一种好方法吗? - Asp.Net, accessing variables from previous page a good approach? 创建一个模型类字段,其中包含来自ASP.NET MVC中另一个表的对象列表 - Create a model class field containing a list of objects from another table in ASP.NET MVC Asp.Net MVC Razor下拉菜单-从ViewModel访问列表 - Asp.Net MVC Razor Dropdown - Accessing list from ViewModel 在ASP.NET页面中将项目从一个列表拖放到另一个列表? - Dragging & dropping items from one list to another in a ASP.NET page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM