查询字符串中的数组 [英] array in query string

查看:99
本文介绍了查询字符串中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在查询字符串中传递数组?

how to pass an array in query string?

推荐答案

尝试此操作
try this
1.aspx

ArrayList arr = new ArrayList();
arr.Add("file1″);
arr.Add("file2″);
arr.Add("file3″);
string arry = String.Join(",", ((string[])arr.ToArray(typeof(String))));
Response.Redirect("1.aspx?file=" + arry);

2.aspx

string[] files = Request["file"].ToString().Split(‘,’);
ArrayList arry = new ArrayList();
foreach (string file in files)
{
arry.Add(file);
}



另一种方式



another way

1.aspx

ArrayList arr = new ArrayList();
arr.Insert(0, "file1″);
arr.Insert(1, "file2″);
arr.Insert(2, "file3″);
Cache["test"] = arr;
arr = null;
Response.Redirect("2.aspx");

2.aspx

ArrayList ary = new ArrayList();
ary.Add(Cache["test"]);
Cache.Remove("test");


我认为除了字符串值之外,您无法通过查询字符串传递Array或任何其他对象.而是可以使用会话变量.

试试这个..

在第一页.

I think you cannot pass Array or any other Objects through Query string except string values. Rather you can use Session Variable.

Try this..

In page One.

//Set
Session["Variable"] = ArrayObj;



在第二页中.



In page Two.

//If String[]

string[] arry = (string[])Session["Variable"];


希望对您有所帮助.


hope it helps..


您不能.
查询字符串仅支持纯文本转换.查询字符串只允许有限数量的数据,而且也不安全,在接收页面的第二件事是,您将以字符串形式获取数据,而不是对象的实际数据类型.

改用Session和Cookies.



您需要将数组放在由任何定界符分隔的singlr字符串中.然后通过查询字符串传递它.
You can''t.
Query sting support only Plain text transformation. Query string allows a limited amount of data and also which is not secure, second thing at the receiving page you will get data as a string which is not your actual datatype of the object.

use Session, Cookies instead.

OR

You need to put your array in singlr string separated by any delimiter. and then pass it through Query string.


这篇关于查询字符串中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆