获取表单值作为剃刀asp.net阵列(Getting the form values as an a

2019-10-17 05:21发布

我有值的形式

           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 />

我想给这个数据库

    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);

   }

这是不工作请帮助

Answer 1:

你应该使用items价值为所有input ,并通过读取值Request.Form.GetValues("items")的方法。

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]);
   }
 }


文章来源: Getting the form values as an array in razor asp.net
标签: asp.net razor