VB中的代码非常少,而且我一直都被卡住了。有人能告诉我这个C#代码的VB等价吗?
... THX
<%= Html.DropDownList("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") %>
答案 0 :(得分:2)
感谢电视让我指向了正确的方向......我在VB中使用数组构造类型进行了挣扎 - 它一直都在那里....
罗伯特在Steven Sanderson的伟大着作Pro ASP.NET MVC Framework的第26页上。非常感谢。
戈登
<% Using Html.BeginForm()%>
<p>Your name: <%=Html.TextBox("Name")%></p>
<p>Your email: <%=Html.TextBox("Email")%></p>
<p>Your phone: <%=Html.TextBox("Phone")%></p>
<p>
Will you attend?
<%=Html.DropDownList("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")%>
</p>
<input type="submit" value="Submit RSVP" />
<% End Using%>
答案 1 :(得分:0)
SelectList的VB等价物应为:
Dim yesNo as SelectList = {
New SelectListItem With { .Text = "Yes, I'll be there", .Value = Boolean.TrueString }, _
New SelectListItem With { .Text = "No, I can't come", .Value = Boolean.FalseString } _
}
http://www.cynotwhynot.com/blog/post/Does-VBNET-have-Collection-Initializers.aspx
答案 2 :(得分:0)
我正在编写Adam Freeman的PRO ASP.NET MVC 5中的教程,并遇到了同样的问题。
本书在c#中,我想用VB编写它们。
这对我有用:
@Html.DropDownListFor(Function(GuestResponse) GuestResponse.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")
答案 3 :(得分:0)
这与Gordon上面的答案相同,但是在Razor语法中,而不是ASPX语法,以防对某人有帮助。 (这对我有帮助: - )
@Using Html.BeginForm()
@<text>
<p>Your name: @Html.TextBoxFor(Function(m) m.Name)</p>
<p>Your email: @Html.TextBoxFor(Function(m) m.Email)</p>
<p>Your phone: @Html.TextBoxFor(Function(m) m.Phone)</p>
<p>
Will you attend?
@Html.DropDownList("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")
</p>
<input type="submit" value="Submit RSVP" />
</text>
End Using