如何通过查询字符串发送数组转换回数组 [英] how to send array by query string convert back into an array
本文介绍了如何通过查询字符串发送数组转换回数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在1.aspx中
In 1.aspx
string[] _array = new string[2];
_array[0]="field 1";
_array[1]="field 2";
Response.Redirect("2.aspx?file=" + _array);
在2.aspx中
In 2.aspx
string[] _array;
_array = (string[])Request.QueryString["file"];
错误:
无法将类型字符串"转换为字符串[]"
error:
Cannot convert type ''string'' to ''string[]''
推荐答案
我认为您无法直接通过查询字符串传递字符串[]. 而是尝试像这样的会话变量.
在第1页中
I think you cannot pass string[] directly through query string.
instead try with session variable like this..
In Page 1
string[] _array = new string[2];
_array[0]="field 1";
_array[1]="field 2";
Session["StrArray"] = _array;
Response.Redirect("2.aspx");
在第2页
In Page 2
string[] strArray = (string[])(Session["StrArray"]);
希望对您有所帮助.
Hope this helps..
在2.aspx中:
In 2.aspx:
string _string;
_string = (string)Request.QueryString["file"];
您只是从QueryString而不是数组中提取字符串.
问候,
Eduard
You are just pulling a string from the QueryString and not an array.
Regards,
Eduard
如果必须这样做,则需要将字符串数组转换为单个字符串,并在完成后将其转换回.最明显的方法是使用一个不会出现在字符串中的分隔符(也许是"|"),并将数组元素组合为一个字符串.然后,您可以使用String.Split将字符串稍后转换回数组.
If you must do that, then you will need to convert the string array into a single string and convert it back when you are done. The most obvious way is to use a separator character that does not appear in your string ("|" perhaps) and combine the array elements into a single string . You can then use String.Split to convert the string back to an array later.
这篇关于如何通过查询字符串发送数组转换回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文