Question

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)%>
Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top