获得发布的值在C#ASP.NET [英] Get posted value In C# ASP.NET

查看:118
本文介绍了获得发布的值在C#ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态的形式,允许动态地添加许多领域,

I have a dynamic form that allow to add many fields dynamically,

我知道如何使用获得的ASPNET单字段的值:的Request.Form [ MyField的],但在这里我有比现场更,我不知道这些字段的数量,因为这些都是动态的。

I Know how to get the value of single field in aspnet using : Request.Form["myField"],but here i have more than field and i dont know the count of these fields since these are dynamic

中的字段名称是订单[]

the fields name is "orders[]"

例如:

<form>
<input type="text" name="orders[]" value="order1" />
<input type="text" name="orders[]" value="order2" />
<input type="text" name="orders[]" value="order3" />
</form>

在PHP中,
I通过访问获得的值作为数组 $ _ POST ['订单'] ;

例如:

$orders = $_POST['orders'];
foreach($orders as $order){
 //execute ...
}

我怎么能做到这一点在C#

how can I do this in c# ?

推荐答案

使用的Request.Form.GetValues

的Request.Form是的NameValueCollection ,可以存储相同的密钥和的ToString 下一个项目集合的对象显示CSV格式的值。

Request.Form is a NameValueCollection, an object that can store a collection of items under the same key and the ToString displays the values in CSV format.

标记:

<input type="text" name="postField[]" />
<input type="text" name="postField[]" />
<input type="text" name="postField[]" />
<input type="text" name="postField[]" />

<asp:Button Text="text" runat="server" OnClick="ClickEv" />



后面的代码:

Code behind:

protected void ClickEv(object sender, EventArgs e)
{
    var postedValues = Request.Form.GetValues("postField[]");

    foreach (var value in postedValues)
    {

    }
}

这篇关于获得发布的值在C#ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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