1
@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 因为它看起来很冗长。

4

1 回答 1

1

你可以像这样使用它:

@Html.ListBox("AdministrationErrorSelected", new SelectList(Model.Select(s => s.AdministrationErrorListBox)), new { @class = "chzn-select" });
于 2011-12-28T19:52:02.583 回答