I’m (desperately) trying to create a link from one of my controllers.
It should look like so:
http://localhost:50074/User/Profile?UserId=17&key=agasgqwefq323432r13dfd
The relevant (though probably erroneous) route:
routes.MapRoute(
"UsersRoute", // Route name
"{controller}/{action}/{userId}/{key}",
new { controller = "User", action = "Profile",userId=UrlParameter.Optional,key=UrlParameter.Optional });
And the link code:
HtmlHelper.GenerateRouteLink(requestContext, RouteTable.Routes, "MyLinkText", "UsersRoute", new RouteValueDictionary(new { userId = userId, key = HashPassword(password) } ), null);
(where I send the request context by: HttpContext.Request.RequestContext.
This currently gives me:
<a href="http://Account/Register/29/E96303852080B94DC230611A3F4806" target="_blank">MyLinkText</a>
(the context from which I call GenerateRouteLink is Account/Register, and I don’t know how to create a correct one, if that’s really needed)
Any help will be much appreciated.
In your route definition the url will be of the form:
so I don’t see how can you possibly expect an url of the form (
{controller}/{action}) when you specify theuseridandkeytokens:Why don’t you simply leave only the default url definition?
Then you could get urls of the desired form by simply: