通过 Pro ASP.NET MVC 书工作,我得到了以下出现在 aspx( View )页面中的代码片段...
<%= 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"); %>
谁能帮我把它转换成 vb.net 等价物。
有什么想法吗?
编辑
更多详情
这是整个代码片段。不确定它会有所帮助,但它就在这里。
<body>
<h1>RSVP</h1>
<% 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[]
{
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") %>
</p>
<input type="submit" value="Submit RSVP" />
<% } %>
</body>
感谢任何帮助。我真的想不通这个。
赛斯
最佳答案
您可以使用一些相当冗长的 VB.NET 代码来完成此操作:
<%
Dim lst As New List(Of SelectListItem)
Dim item1 As New SelectListItem
item1.Text = "Yes, I'll be there"
item1.Value = Boolean.TrueString
lst.Add(item1)
Dim item2 As New SelectListItem
item2.Text = "No, I can't come"
item2.Value = Boolean.FalseString
lst.Add(item2)
%>
<%=Html.DropDownList("WillAttend", lst, "Choose an option")%>
诀窍是读取函数参数并提供适当的参数。有时我们习惯了更神秘的语法而忘记了简单的变量声明和赋值。 DropDownList 期望 SelectListItem 的 IEnumerable 作为第二个参数,所以这就是我们给它的。每个 SelectListItem 都应该提供它的值和文本字段。我不明白的是为什么 SelectListItem 的构造函数不提供这两项(可能加上一个“选定的” bool 值。)
关于c# - 如何将以下 asp.net mvc c# 代码片段呈现为 vb.net 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1225606/