Url.Action with RouteValueDictionary with Protocol
asp.net-mvc
Solution
The overload that you are using expects type "object" for the parameter where you are passing the `RouteValueDictionary`. For some reason this is causing the issue, maybe something to do with .ToString()? Use an overload that accepts a `RouteValueDictionary` and this should work.
To test this, add a hostName argument to select the overload shown below:
EDIT
You could use this extension in your project to add the overload that you require to Url.Action. Internally it will resolve and add the hostName from the request.
public static string Action
(this UrlHelper helper, string action,
string controller, RouteValueDictionary routeValues, string protocol)
{
string hostName = helper.RequestContext.HttpContext.Request.Url.Host;
return helper.Action(action, controller, routeValues, protocol, hostName);
}
Problem
been looking at this for a while, and feel like I am just being stupid want to get some more eyes on it.. I need to generate a full URL, (e.g. `http://www.domain.com/controller/action?a=1&b=2`), generally I just use `Url.Action` to do this with no problems by specifying the protocol: ``` var url = Url.Action("Action", "Controller", new { a = 1, b = 2 }, "http"); ``` I've started putting together a class that returns a `RouteValueDictionary` to make these anonymous objects disappear. However, I can't get it to work alongside the helper. ``` var x = Url.Action("Action", "Controller", new RouteValueDictionary(new { a = 1, b = 2 }), "http"); // "http://127.0.0.1/Controller/Action?Count=2&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D", var y = Url.Action("Action", "Controller", new { a = 1, b = 2 }, "http"); // "http://127.0.0.1/Controller/Action?a=1&b=2" ``` Any pointers that lead to a facepalm greatly appreciated :) Update: It's probably best to clarify that in the above sample, I need to get the '`X`' variable working correctly, since the RouteValueDictionary is created elsewhere in code. Assume that the RouteValueDictionary is correct. I just don't understand why this works with anonymous object, but the same object wrapped in the same object wrapped in a `RouteValueDictionary` makes the helper freak out.