Skip to content

Instantly share code, notes, and snippets.

@jbogard
Created December 11, 2013 21:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbogard/7918898 to your computer and use it in GitHub Desktop.
Save jbogard/7918898 to your computer and use it in GitHub Desktop.
Hyprlinkr + UrlHelper
using System;
using System.Linq.Expressions;
using System.Web.Http;
using System.Web.Http.Routing;
using Ploeh.Hyprlinkr;
public static class UrlHelperExtensions
{
public static Uri Link<T, TResult>(this UrlHelper helper, Expression<Func<T, TResult>> expression)
where T : ApiController
{
var linker = new RouteLinker(helper.Request);
return linker.GetUri(expression);
}
public static Uri Link<T>(this UrlHelper helper, Expression<Action<T>> expression)
where T : ApiController
{
var linker = new RouteLinker(helper.Request);
return linker.GetUri(expression);
}
}
@jbogard
Copy link
Author

jbogard commented Dec 11, 2013

now in a controller action, just do

Url.Link<FooController>(c => c.Get(id))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment