在 asp.net mvc4(vb) 中将项目添加到 dropdownlistfor helper
add item to dropdownlistfor helper in asp.net mvc4(vb)
请在asp.netmvc4中转换此代码VB
@Html.DropDownListFor(x => x.WillAttend, new[]
{
new SelectListItem() {Text = "Yes, I'll be there", Value = bool.TrueString},
new SelectListItem() {Text = "No, I can't come", Value = bool.FalseString}
}, "Choose an option")
当我像这样在 VB 中编写上面的 C# 代码时
@Html.DropDownListFor(Function(x) x.WillAttend, New SelectList( New SelectListItem With {.Text = "Yes, I'll be there", .Value = "p"}, New SelectListItem With {.Text = "No, I can't come", .Value = "p"})
我收到错误:无法将类型 'System.Web.Mvc.SelectListItem' 的对象转换为类型 'System.Collections.IEnumerable'。
@Html.DropDownListFor(Function(x) x.WillAttend, New SelectListItem() {New SelectListItem With {.Text = "Yes, I'll be there", .Value = Boolean.TrueString}, New SelectListItem With {.Text = "No, I can't come", .Value = Boolean.FalseString}}, "Choose an option")
请在asp.netmvc4中转换此代码VB
@Html.DropDownListFor(x => x.WillAttend, new[]
{
new SelectListItem() {Text = "Yes, I'll be there", Value = bool.TrueString},
new SelectListItem() {Text = "No, I can't come", Value = bool.FalseString}
}, "Choose an option")
当我像这样在 VB 中编写上面的 C# 代码时
@Html.DropDownListFor(Function(x) x.WillAttend, New SelectList( New SelectListItem With {.Text = "Yes, I'll be there", .Value = "p"}, New SelectListItem With {.Text = "No, I can't come", .Value = "p"})
我收到错误:无法将类型 'System.Web.Mvc.SelectListItem' 的对象转换为类型 'System.Collections.IEnumerable'。
@Html.DropDownListFor(Function(x) x.WillAttend, New SelectListItem() {New SelectListItem With {.Text = "Yes, I'll be there", .Value = Boolean.TrueString}, New SelectListItem With {.Text = "No, I can't come", .Value = Boolean.FalseString}}, "Choose an option")