Asp Mvc 4过滤器表单返回null到控制器

时间:2013-06-07 20:28:12

标签: .net asp.net-mvc-4 razor

我正在开发ASP MVC 4 Web应用程序,用户可以按特定功能过滤项目。我在我的视图中使用表单然而在表单提交null传递给控制器​​

以下是代码段

查看:

 @using (Html.BeginForm("Category", "Catalog", new {filteringModel = Model.ProductFilteringModel}))
        {
        <div>
            <div class="filter-item">
                <h1 id="filter-parameters">
                    по  параметрам
                    <br/>
                </h1>
                <div class="filter-field-input">
                    @Html.CheckBoxFor(x => x.ProductFilteringModel.ShowAvailable)    
                </div>
                <div class="filter-field-title">
                    @Html.LabelFor(x => x.ProductFilteringModel.ShowAvailable)
                </div>
            </div>
            <div class="filter-item">
                <ul class="filter-field-list">
                @foreach (var skinType in Model.ProductFilteringModel.SkinTypes)
                {
                    <li class="filter-list-item">
                        <div class="filter-field-input">
                            @Html.CheckBox(skinType.Title, false)
                        </div>
                        <div class="filter-field-title">
                            @Html.Label(skinType.Title)
                        </div>
                    </li>
                }
                </ul>
            </div>
            <div class="filter-item">
                <ul class="filter-field-list">
                    @foreach (var expected in Model.ProductFilteringModel.ExpectedResults)
                    {
                        <li class="filter-list-item">
                            <div class="filter-field-input">
                                @Html.CheckBox(expected.Title, false)
                            </div>
                            <div class="filter-field-title">
                                @Html.Label(expected.Title)
                            </div>
                        </li>
                    }
                </ul>
             </div>
            <input type="submit" value="Filter"/>
        </div>
        }

控制器:

       public ActionResult Category(int categoryId, CatalogPagingFilteringModel command, ProductFilteringModel filteringModel)
    {
     //Do something
    }

我的过滤模式:

    public class ProductFilteringModel
{
    public bool ShowAvailable { get; set; }
    public List<ItemFeatureModel> SkinTypes { get; set; }
    public List<ItemFeatureModel> ExpectedResults { get; set; }
}

public class ItemFeatureModel
{
    public string Id { get; set; }
    public string Title { get; set; }
    public bool Selected { get; set; }
}

0 个答案:

没有答案