有人能告訴我我在做什麼在Dropdownlist查看錯誤?我認爲它期望SelectList的下拉列表?先謝謝你。WebGrid中的下拉列表 - MVC4
我的模型:
public class AppointmentModel
{
public int CustomerID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public List<DateTime> ApptDates { get; set; }
}
查看:
@{
var grid = new WebGrid(Model, rowsPerPage: ViewBag.RowsPerPage);
@grid.GetHtml(columns: grid.Columns(
grid.Column(columnName: "LastName", header: "Last Name", canSort: true, format: @<text>@item.LastName</text>),
grid.Column(columnName: "LastName", header: "First Name", canSort: true, format: @<text>@item.Firstname</text>),
grid.Column(columnName: "ApptDates", header: "Appointment Dates", format: @Html.DropDownList(@item.ApptDates))
));
}
以下更改解決了該問題:
public class AppointmentModel
{
public int CustomerID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public DateTime ApptDt { get; set; }
public IEnumerable<SelectListItem> ApptDatesSelectList { get; set; }
}
查看
@{
var grid = new WebGrid(Model, rowsPerPage: ViewBag.RowsPerPage);
@grid.GetHtml(columns: grid.Columns(
grid.Column(columnName: "LastName", header: "Last Name", canSort: true, format: @<text>@item.LastName</text>),
grid.Column(columnName: "LastName", header: "First Name", canSort: true, format: @<text>@item.Firstname</text>),
grid.Column(columnName: "ApptDates", header: "Appointment Dates", format: @<text>@Html.DropDownList("ApptDt", (IEnumerable<SelectListItem>)@item.ApptDatesSelectList)</text>)
));
}
是ApptDates日期的委任名單還是對潛在的約會日期列表? – Maess
AppDates是預約日期的列表。 – rk1962