Reputation: 6122
I translated this from C# to VB.NET
C#:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
var config = new HttpConfiguration() { EnableTestClient = true };
routes.Add(new ServiceRoute("api/contacts", new HttpServiceHostFactory() { Configuration = config }, typeof(ContactsApi)));
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
VB.NET:
Public Shared Sub RegisterRoutes(routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
Dim config = New HttpConfiguration() With { _
Key .EnableTestClient = True _
}
routes.Add(New ServiceRoute("api/contacts", New HttpServiceHostFactory() With { _
Key .Configuration = config _ <-----------Name of field or property being initialized in an object initializer must start with '.'.
}, GetType(ContactsApi)))
' Route name
' URL with parameters
' Parameter defaults
routes.MapRoute("Default", "{controller}/{action}/{id}", New With { _
Key .controller = "Home", _
Key .action = "Index", _
Key .id = UrlParameter.[Optional] _
})
End Sub
But I get an error (placed inline in VB.NET code):
What would the correct translation?
Upvotes: 1
Views: 3721
Reputation: 224858
Remove the Key
.
Public Shared Sub RegisterRoutes(routes As RouteCollection)
routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
Dim config = New HttpConfiguration() With { _
.EnableTestClient = True _
}
routes.Add(New ServiceRoute("api/contacts", New HttpServiceHostFactory() With { _
.Configuration = config _ <-----------Name of field or property being initialized in an object initializer must start with '.'.
}, GetType(ContactsApi)))
' Route name
' URL with parameters
' Parameter defaults
routes.MapRoute("Default", "{controller}/{action}/{id}", New With { _
.controller = "Home", _
.action = "Index", _
.id = UrlParameter.[Optional] _
})
End Sub
Upvotes: 3