@model MedicalVariance.Models.ViewModels.IndividualProfile
@Html.ListBox("AdministrationErrorSelected", Model.AdministrationErrorListBox, new { @class = "chzn-select" })
它看起来很棒但是工作得很好!但是我想创建一个IEnumerable,因为我想使用webgrid。
@model IEnumerable<MedicalVariance.Models.ViewModels.IndividualProfile>
@Html.ListBox("AdministrationErrorSelected", foreach(var model in Model)model.AdministrationErrorListBox, new { @class = "chzn-select" })
@{
var grid = new WebGrid(source:Model, canPage: true, rowsPerPage: 5,fieldNamePrefix:"details");
.... wouldnt work if the Model was not IEnumerable...
}
有更好的方法吗?我不喜欢使用foreach,因为它看起来很冗长。
答案 0 :(得分:1)
你可以像这样使用它:
@Html.ListBox("AdministrationErrorSelected", new SelectList(Model.Select(s => s.AdministrationErrorListBox)), new { @class = "chzn-select" });