有人可以在View for Dropdownlist中告诉我我做错了什么吗?我认为它是期待SelectList的下拉列表?先感谢您。
我的模特:
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>)
));
}
答案 0 :(得分:4)
假设我的评论的答案是每个约会都有一个日期,您首先需要在特定日期为模型添加属性:
public class AppointmentModel
{
public int CustomerID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public DateTime AppointmentDate {get; set;}
public List<DateTime> ApptDates { get; set; }
}
然后,在SelectList
完成后,您将需要进行潜在约会,您可以这样实施:
@{
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(@item.AppointmentDate, yourSelectList )</text>)
));
}