选择不显示绑定项目的帮助程序标记

时间:2016-09-15 13:04:58

标签: razor asp.net-core asp.net-core-mvc

我试图显示要过滤的选项的下拉列表,但是选择的助手标记未显示有界列表。

这是家庭控制器

public IActionResult Index(string SelectedClinic)
    {
        GetReservationsAsync();

        HomeIndexvmIns.Clinics = new SelectList(_clinicsLookup, "Id", "ClinicName");

        return View(HomeIndexvmIns);
    }

这是 HomeIndexViewModel

public HomeIndexViewModel()
    {
        Reservations = new List<ReservationViewModel>();
    }

    public List<ReservationViewModel> Reservations { get; set; }
    public SelectList Clinics { get; set; }
    public string SelectedClinic { get; set; }

这是索引视图

@model schedule.ViewModels.HomeIndexViewModel


<form asp-controller="Home" asp-action="Index" method="post">
<p>
    <select asp-for="SelectedClinic" asp-items="Model.Clinics"></select>
</p>
</form>


<table class="table">
<tbody>
<thead>
<tr>
    <th>
        Reservation Id
    </th>
    <th>
        Start Date/Time
    </th>
    <th>
        End Date/Time
    </th>
    <th>
        Status
    </th>
    <th>
        Clinic
    </th>
    <th></th>
</tr>
</thead>
@foreach (var item in Model.Reservations)
{

    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Id)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.StartDateTime)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.EndDateTime)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Status)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Clinic)
        </td>
    </tr>
}
</tbody>
</table>

我尝试将SelectList更改为IEnumerable of Clinics或SelectListItems列表,但仍然没有选项显示在下拉列表中。

修改

我刚刚用

更改了选择标记
@Html.DropDownListFor(m => m.SelectedClinic, Model.Clinics)

它呈现的正确,我仍然想知道选择标签为什么不起作用。

0 个答案:

没有答案