2012-07-20 111 views
0

我在网上搜索,我想我的代码应该是正确的,但是当你提交的模型领域始终是0 型号:MVC html.dropdownlistfor没有更新模型场

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) 
     { 
... 
} 

的下拉列表显示正常,但不管是什么I S选择它将0发送给控制器。

回答

0

尝试:

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

,你不需要Html.HiddenFor ..只是确保一切都包裹在一个<form>元素,当你提交,所有的值应绑定到你的模型(如只要您在接收操作中拥有[HttpPost]属性