0 c# error-handling asp.net-mvc
我刚开始学习ASP.NET MVC 3表单这本书,我有一个例子,从它的一个问题.
我总是得到这个错误
描述:编译服务此请求所需的资源时发生错误.请查看以下特定错误详细信息并相应地修改源代码.
编译器错误消息:CS0103:当前上下文中不存在名称"Text"
这是代码:
@Html.DropDownListFor(p => p.WillAttend, new[]
{
new SelectListItem(), Text = "Yes I'll be there", Value = bool.TrueString,
new SelectListItem(), Text = "No, I can't come", Value = bool.FalseString
}, "Chose option")
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?
你忘记了一些{}:
@Html.DropDownListFor(p => p.WillAttend, new[]
{
new SelectListItem(){ Text = "Yes I'll be there", Value = bool.TrueString},
new SelectListItem(){ Text = "No, I can't come", Value = bool.FalseString}
}, "Chose option")
Run Code Online (Sandbox Code Playgroud)