0

I have a class named "AirLineSession":

    public ExtendedList listCo { get; set; }
    public ExtendedList listBa { get; set; }

    public bool SortbyRating { get; set; }
    public AirLineSession()
    {
        listCo = new ExtendedList();
        listBa = new ExtendedList();
    }

In my view I have:

@Html.HiddenFor(m => m.listBa)
@Html.HiddenFor(m => m.listCo)
@Html.DropDownListFor(a => a.SortbyRating, new[] { new SelectListItem { Text = "Sort by rating", Value = "true" }, new SelectListItem { Text = "Sort by frice", Value = "false" } })

When I summit this view, only data of SortByRating is passed to the model in Controller, listBa and listCo aren't passed. I don't know why.
Anyone help me, thanks.

4

2 回答 2

0

你能发布 ExtendedList 类的代码吗?原因是 asp.net mvc 不知道如何为 ExtendedList 复杂类型创建所有 Hidden。在这种情况下,您应该为两个集合的对象和集合的每个字段添加隐藏,例如:

@for(var i = 0; i < Model.listCo.Lenght; i++)
{
    @Html.HiddenFor(model => model.listCo[i].Property1)
    @Html.HiddenFor(model => model.listCo[i].Property2)
    @Html.HiddenFor(model => model.listCo[i].Property3)
}

并且:

@for(var i = 0; i < Model.listBa.Lenght; i++)
{
    @Html.HiddenFor(model => model.listBa[i].Property1)
    @Html.HiddenFor(model => model.listBa[i].Property2)
    @Html.HiddenFor(model => model.listBa[i].Property3)
}
于 2013-08-05T13:05:27.123 回答
0

如果您使用 Forended html 帮助程序,请确保您已按模型将它们的值传递给相关视图。但如果没有,您应该为 ViewBag 等一些动态工具设置值,然后使用以下代码:

@Html.Hidden("listBa", ViewBag.listba)
@Html.Hidden("listCo", ViewBag.listco)
于 2013-08-05T13:08:11.723 回答