Reputation: 4610
There is very little code out there that is in VB, and i'm getting stuck all the time. Can someone tell me the VB equivalent of this C# code?
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") %>
Upvotes: 2
Views: 4196
Reputation: 212
This is the same as Gordon's answer above, but in Razor syntax, instead of ASPX syntax, in case that would be helpful to someone. (It was helpful to me:-)
@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
Upvotes: 0
Reputation: 1
I was coding the tutorials in the PRO ASP.NET MVC 5 book from Adam Freeman and had the same problem.
The book is in c# and I wanted to code them in VB.
This was what worked for me :
@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")
Upvotes: 0
Reputation:
Thanks TV for pointing me in the right direction... I struggled with nutting the array Constructer Type in VB - It was right there all the time....
Robert's on page 26 of Steven Sanderson's great book, Pro ASP.NET MVC Framework.
Many thanks.
Gordon
<% 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%>
Upvotes: 2
Reputation: 180787
The VB equivalent for your SelectList should be:
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
Upvotes: 0