可以通过Collection.Request.Form我循环? [英] Can I loop through a Collection.Request.Form?

查看:131
本文介绍了可以通过Collection.Request.Form我循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些复选框有唯一的ID。是否有可能找到所有的复选框+ uniquenum的形式集合?

像 -

 的foreach(在Collection.Request.Form VAR项目[复选框+与UniqueIDNum])
{
    // code
}
 

解决方案

没有。

相反,你可以通过所有的钥匙环,并检查他们是否开始与复选框

例如:

 的foreach(在的Request.Form字符串键){
    如果继续(key.StartsWith(复选框)!);
    ...
}
 

的<一个href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.nameobjectcollectionbase.getenumerator.aspx">NameValueCollection枚举返回键为字符串。

I have some checkboxes with a unique id. is it possible to find all the checkbox+uniquenum in a form collection?

something like -

foreach (var item in Collection.Request.Form["checkbox" + with UniqueIDNum])
{
    //code
}

解决方案

No.

Instead, you can loop through all of the keys, and check whether they start with checkbox.

For example:

foreach(string key in Request.Form) {
    if (!key.StartsWith("checkbox")) continue;
    ...
}

The NameValueCollection enumerator returns keys as strings.

这篇关于可以通过Collection.Request.Form我循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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