0

我在网上搜索,我认为我的代码应该是正确的,但是当您提交模型字段时始终为 0。模型:

 public class ProductsModel
    {
        public List<Products> ProductCommission;
        public List<ProductGroupType> ProductGroupType;
        public  CommissionType CommissionType;
        public int FilterProductGroupTypeId;
        public string Status;

    }

看法:

   @Html.DropDownListFor(m => Model.FilterProductGroupTypeId, new SelectList(Model.ProductGroupType, "ID", "Description"), "All")
    @Html.HiddenFor(m => Model.FilterProductGroupTypeId);
      @*  @Html.ActionLink("Filter", "FilterProductTypes", "Products", new { filterid = Model.FilterProductGroupTypeId });*@
 <a href="@Url.Action("FilterProductTypes", "Products", new { filterid  = Model.FilterProductGroupTypeId})">Filter</a>

控制器:

 public ViewResult FilterProductTypes(int filterid)
        {
...
}

下拉列表显示正确,但无论我选择什么,它都会向控制器发送 0。

4

1 回答 1

0

尝试:

@Html.DropDownListFor(m => m.FilterProductGroupTypeId ..etc)

而且您不需要Html.HiddenFor.. 只需确保所有内容都包含在一个<form>元素中,并且当您提交时,所有值都应绑定到您的模型(只要您[HttpPost]在接收操作上有属性

于 2012-07-20T03:28:25.253 回答