Question

In one of my controller actions, I'm generating some XML. One of the attributes in that XML is an href to another controller and action, with some parameters. The XML should look something like this:

<projects>
  <project id="42" name="Project X", href="/projects/42"/>
  <!-- etc. -->
</projects>

I don't mind if the URL is relative or absolute, but my question is this: how do I generate the URL in the controller code, in a type-safe way?

In other words, how do I do what HtmlHelper.ActionLink does, but from a controller?

Was it helpful?

Solution

Found it by using Reflector:

string href = Url.Action("DetailsAsXml", new { projectId = item.Id });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top