0

当用户从任何一个下拉列表中选择某个值时,我需要将三个下拉列表中的值传递给控制器​​。我尝试过这样,但仅传递所选下拉列表中的值,其他值为空值,任何帮助将不胜感激。

看法

      @@using (Html.BeginForm("GetFilterValues","Home",FormMethod.gET))
          {   
            @Html.DropDownList("FClass", ViewBag.Market as SelectList,  new { id = "Market" , onchange = "$(this).parents('form').submit();" })
           }

      @using (Html.BeginForm("GetFilterValues","Home",FormMethod.Get))
                    {
                          @Html.DropDownList("FClass", ViewBag.Class as SelectList,  new { id = "FClass" , onchange = "$(this).parents('form').submit();" })
                      }

              </td>
                        <td>
                 @Html.Label("Status")
                            </td>
               <td>
                    @using (Html.BeginForm("GetFilterValues","Home",FormMethod.Get))
                    {
                                                 @Html.DropDownList("Status", ViewBag.Status as SelectList,  new { id = "Status" , onchange = "$(this).parents('form').submit();" })

                    }

控制器 [Httpget]

      public void GetFilterValues()
       {
        string  market = this.Request.Form.Get("Market");
        string fclass = this.Request.Form.Get("FClass");
        string status = this.Request.Form.Get("Status");
        }
4

1 回答 1

0

通过 POST 尝试单个表单,并使用这样的 FormCollection 按名称提取值...

看法:

@using (Html.BeginForm("GetFilterValues","Home", FormMethod.Post))
    {     
          @Html.DropDownList("nameMarket", ViewBag.Market as SelectList,  new { id = "Market" , onchange = "$(this).parents('form').submit();" })
          @Html.DropDownList("nameClass", ViewBag.Class as SelectList,  new { id = "FClass" , onchange = "$(this).parents('form').submit();" })
          @Html.DropDownList("nameStatus", ViewBag.Status as SelectList,  new { id = "Status" , onchange = "$(this).parents('form').submit();" })
    }

控制器:

[HttpPost]
public void GetFilterValues(FormCollection collection) {
    string  market = Convert.ToString(collection["nameMarket"]);
    string fclass = Convert.ToString(collection["nameClass"]);
    string status = Convert.ToString(collection["nameStatus"]);
}
于 2013-10-04T03:52:32.717 回答