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" }

})

 

你可能感兴趣的:(asp.net)