Context.Request getValues和多个select元素

时间:2015-03-31 14:37:34

标签: c# ashx generic-handler

我试图理解context.Request中的Form和QueryString的GetValues

我有一个这样的网址,是从多个选择html元素上的ajax处理程序生成的

generic.ashx?tags=1&tags=2

理论上不应该(通过邮寄提交)将字符串标签设置为1,2?

string[] tags = context.Request.Form.GetValues("tags");

我也尝试过使用get方法,使用查询字符串或只是上下文请求,到目前为止没有任何内容

string[] tags = context.Request.QueryString.GetValues("tags");
string[] tags = context.Request.GetValues("tags");

我的底线是我想构建一个sql where子句

int tagscount = tags.Count();

      string sWhere ="";

        if (tagscount != 0) {
          sWhere ="Where (";
          for (int i = 0; i < tagscount; i++)

            {

                sWhere += " tag_id ="+tags[i]+")";
                if (i < tagscount -1){
                  sWhere += " OR ";
                }

              }
              sWhere += ")";
            }

但老实说,我会很高兴在这一点上表明我的字符串正在填充

results = string.Format("{{ \"tags\": {0}  }}",tags);
context.Response.Write(results);

1 个答案:

答案 0 :(得分:1)

GetValues()应该工作,而不是严格地将值获取到string [],尝试使用var和iterate从中获取每个值。

var values = context.Request.QueryString.GetValues("tags");
foreach (var item in values)
{
    //do your thing
}