C# Listbox html帮助程序向Post函数返回零个对象

C# Listbox html帮助程序向Post函数返回零个对象,c#,html,model-view-controller,listbox,html-helper,C#,Html,Model View Controller,Listbox,Html Helper,我正在尝试为我创建的模块获取一个列表框。选择器工作,可选择实体的标题出现,但控制器中没有返回到Post功能的数据 我不知道你需要什么来帮助我,但这里至少有html代码 HTML代码: <div class="field required"> @Html.LabelFor(model => model.Sessions) @Html.ListBox("Sessions", new SelectList(Model.Sessions, "Id

我正在尝试为我创建的模块获取一个列表框。选择器工作,可选择实体的标题出现,但控制器中没有返回到Post功能的数据

我不知道你需要什么来帮助我,但这里至少有html代码

HTML代码:

    <div class="field required">
        @Html.LabelFor(model => model.Sessions)
        @Html.ListBox("Sessions", new SelectList(Model.Sessions, "Id", "Title", 1));
        @Html.ValidationMessageFor(model => model.Sessions)
    </div>
在控制器中使用ViewBag

entity.ID将是您要选择的值

@Html.DropDownList("Sessions", "Select Sessions")

它不是ListBoxFor,因此它不会将值绑定到POST上的任何属性。如果它是一个SelectList,将它绑定到一个int,比如@Html.DropDownListFormodel=>model.SessionId,new SelectListModel.Sessions,Id,Title,1,其中在您的模型中SessionId将是一个int属性-列表中所选项目的索引。感谢您的回答,我将其更改为:@Html.ListBoxFormodel=>model.Id,新的SelectListModel.Sessions,Id,Title,1,但我仍然会将控制器设置为null。模块会话不包含integer ID属性,但我尝试使用SessionViewModel来包含,但也不起作用。有什么想法吗?我能用一种更简单的方式来做吗?
@Html.DropDownList("Sessions", "Select Sessions")