0

我正在使用这行代码来调用自定义编辑器模板。

@Html.Editor("country", "CustomDropdown", CountrySelectionList)

我现在想CountrySelectionList在 CustomDropdown 视图中访问并遍历其项目:我该怎么做? CountrySelectionList 属于SelectList类型。

这是我试图在视图中做的:

@model SelectList

@foreach (var item in Model.Items)
{
    <div>@item.ToString()</div>
}

但是遇到了Object reference not set to an instance of an object错误。

那么我该怎么做呢?我想做我自己的下拉列表:如果不迭代 SelectList 的键 + 值对,这是不可能的。

4

1 回答 1

0
@Html.Partial("~/Views/Shared/EditorTemplates/CustomDropdown.cshtml", CustomerCountrySelectionList)

模型直接进入视图。

@Html.Editor(),尽管有 6 个重载,但可能没有一个设计用于在自定义编辑器中传递模型。

于 2013-07-24T08:04:23.270 回答