Note that there are some explanatory texts on larger screens.

plurals
  1. POUrl.Action with RouteValueDictionary with Protocol
    text
    copied!<p>been looking at this for a while, and feel like I am just being stupid want to get some more eyes on it..</p> <p>I need to generate a full URL, (e.g. <code>http://www.domain.com/controller/action?a=1&amp;b=2</code>), generally I just use <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.action(v=vs.108).aspx" rel="noreferrer"><code>Url.Action</code></a> to do this with no problems by specifying the protocol:</p> <pre><code>var url = Url.Action("Action", "Controller", new { a = 1, b = 2 }, "http"); </code></pre> <p>I've started putting together a class that returns a <code>RouteValueDictionary</code> to make these anonymous objects disappear. However, I can't get it to work alongside the helper.</p> <pre><code>var x = Url.Action("Action", "Controller", new RouteValueDictionary(new { a = 1, b = 2 }), "http"); // "http://127.0.0.1/Controller/Action?Count=2&amp;Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&amp;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&amp;b=2" </code></pre> <p>Any pointers that lead to a facepalm greatly appreciated :)</p> <p><strong>Update:</strong></p> <p>It's probably best to clarify that in the above sample, I need to get the '<code>X</code>' variable working correctly, since the RouteValueDictionary is created elsewhere in code. Assume that the RouteValueDictionary is correct.</p> <p>I just don't understand why this works with anonymous object, but the same object wrapped in the same object wrapped in a <code>RouteValueDictionary</code> makes the helper freak out.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload