ASP.NET MVC5 DropDownListFor中bool?类型赋值为null的解决办法

 

使用ToString() 将null转换为string即可

@Html.DropDownListFor(model => model.AllowedPublished,
  new List<SelectListItem> {
  new SelectListItem() { Text = "未审核", Value = (null as bool?).ToString() },
  new SelectListItem() { Text = "已通过", Value = "true" },
  new SelectListItem() { Text = "未通过", Value = "false" }
})

 

posted @ 2015-04-15 08:18  LzxHahaha  阅读(531)  评论(0编辑  收藏  举报