获取表单值作为剃刀asp.net数组 [英] Getting the form values as an array in razor asp.net

查看:102
本文介绍了获取表单值作为剃刀asp.net数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有值的表格

           Price  <input type="text" name="items[price]" value="" /> <br />
       Condition  <input type="text" name="items[condition]" value="" /> <br />
           Brand  <input type="text" name="items[brand]" value="" /> <br />

我想送这个数据库

I want to send this to database

    string[] allitems = Request.Form["items"];
    var db2x = Database.Open("mystring");

    foreach (var item in allitems)
    {
       var insertCommand2x = "INSERT INTO Classifieds_attr_value (AttrId,CarBikeId,AttrVal) VALUES(@0,@1,@2)";
       db2x.Execute(insertCommand2x, AttrId, CarBikeId, AttrVal);

   }

这是不工作请帮助

推荐答案

您应该使用项目所有输入值和读取通过 Request.Form.GetValues​​值(项目)方法。

You should have to use items value for all input and read values via Request.Form.GetValues("items") method.

Price      <input type="text" name="items" value="" /> <br />
Condition  <input type="text" name="items" value="" /> <br />
Brand      <input type="text" name="items" value="" /> <br />

和读取数值,

string []items=Request.Form.GetValues("items");
if(items!=null){
   //read
}

或者选择的名称的属性不同的值。

Price      <input type="text" name="price" value="" /> <br />
Condition  <input type="text" name="condition" value="" /> <br />
Brand      <input type="text" name="brand" value="" /> <br />

和读取键值​​,

string[] keys = Request.Form.AllKeys;
if (keys!= null)
 {
  foreach (var key in keys)
   {
   Response.Write("<br/>" + key + " " + Request.Form[key]);
   }
 }

这篇关于获取表单值作为剃刀asp.net数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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