-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Url.RouteUrl can be simpler for common patterns. #1966
Comments
What about if that method returned a builder kinda like UriBuilder that you could then use to get the full url?
|
So like this?
Or
Still seems like a lot of moving parts to do something I'm gonna do ALL DAY LONG. |
var myString = Url.RouteUrlAsBuilder("GetDinnerById", new { id = dinner.DinnerId }).ToFull(); is much better |
@rustd But why do I need to RouteUrlAsBuilder? What's the Builder? What's wrong with RouteUrlAsAbsolute and don't even bother with the ToFull. The ToString is implied. |
This does feel a bit tedious... I'd almost want the scheme and host to default to the values the current request came in on. Most of the time, I think these values would stay the same from one request to the next |
Add an extension method in your code to remove repetitive tediousness? |
WebApi had this feature named link - We should bring it back: From WebApi code public class UrlHelper
{
// lots of other methods here
// ......
//
public virtual string Link(string routeName, object routeValues)
{
return Link(routeName, new HttpRouteValueDictionary(routeValues));
}
/// <summary>
/// Creates an absolute URL using the specified route and route data.
/// </summary>
/// <param name="routeName">The name of the route to use for generating the URL.</param>
/// <param name="routeValues">The route data to use for generating the URL.</param>
/// <returns>The generated URL.</returns>
[SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "It is safe to pass string here")]
public virtual string Link(string routeName, IDictionary<string, object> routeValues)
{
string link = Route(routeName, routeValues);
if (!String.IsNullOrEmpty(link))
{
link = new Uri(Request.RequestUri, link).AbsoluteUri;
}
return link;
}
} |
Fantastic. On Fri, Feb 6, 2015 at 9:42 AM, Yishai Galatzer notifications@github.com
Scott Hanselman |
See #2810 for AbsoluteRouteUrl, AbsoluteRouteAction and AbsoluteContent methods added to UrlHelper. |
This is a common pattern:
I find
mixing two things and a little tedious. The last part
is kind of administrivia. Can we make it more like?
or
The text was updated successfully, but these errors were encountered: