views:

365

answers:

2

I think in C# you can create in-line RouteValueDictionary instances like this:

<%=Html.RouteLink(Model.Name, "SomeRoute", new { id = Model.Id }) %>

What's the equivalent in Visual Basic?

This works, but is quite wordy:

<%
    Dim d As New RouteValueDictionary()
    d.Add("id", Model.Id)
%>

<%=Html.RouteLink(Model.Name, "SomeRoute", d)%>
+2  A: 
<%=Html.RouteLink(Model.Name, "SomeRoute", New With {.id = Model.Id})%>
Zack Peterson
+1  A: 

Just to clarify, you're not actually creating an inline RouteValueDictionary with this syntax. You're creating a new anonymous type, and using the RouteLink(linkText As String, routeName As String, routeValues As Object) overload. This overload uses reflection (I assume) internally to add the properties of your anonymous object and their values to a RouteValueDictionary to create the link.

Mike Powell