问题:
你好,我的DropDownListFor突然遇到了麻烦,而且工作得很好。我正在设计我的网络应用程序,但没有在dropdownlistfor
上更改任何内容 <!-- Genre -->
<div class="form-group">
@Html.LabelFor(m => m.Genre)
@Html.DropDownListFor(m => m.Genre, new SelectList(Model.Genres.OrderBy(n=>n.Name), "Id", "Name"), "Select Genre", new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Genre)
</div>
在控制器
中 [Authorize]
public ActionResult Create()
{
var viewModel = new GigFormViewModel
{
Genres = _context.Genres.ToList()
};
return View(viewModel);
}
好的,这就是我的问题的视觉效果:
Yet the item is selected and will save properly to database
所以它只是让我感到困扰的视觉效果......节省,其他一切都很好。
我甚至检查过项目的元素和颜色都是黑色试图改变显示框的背景,以防字体是白色的,所以我可以看到它但是没有,选择根本就不显示。
编辑:Viewmodel - &gt;
public class GigFormViewModel
{
[Required]
public string Name { get; set; }
[Required]
public string Venue { get; set; }
[Required]
[FutureDate]
public string Date { get; set; }
[Required]
[ValidTime]
public string Time { get; set; }
[Required]
public int Genre { get; set; }
public IEnumerable<Genre> Genres { get; set; }
public DateTime GetDateTime()
{
return DateTime.Parse(string.Format("{0} {1}", Date, Time));
}
和类型课
public class Genre
{
public byte Id { get; set; }
[Required]
[StringLength(255)]
public string Name { get; set; }
}
答案 0 :(得分:0)
尝试此更改
@Html.DropDownListFor(m => m.Genre, new SelectList(Model.Genres.OrderBy(n=>n.Name), "Id", "Name",0), "Select Genre", new { @class = "form-control" })
可能会对你有用..;)