/// <summary> /// Returns an URL to entry thumbnail image. /// Currently only used for album and artist main images. /// /// Gets the URL to the static images folder on disk if possible, /// otherwise gets the image from the DB. /// </summary> /// <param name="urlHelper">URL helper. Cannot be null.</param> /// <param name="imageInfo">Image information. Cannot be null.</param> /// <param name="size">Requested image size.</param> /// <param name="fullUrl"> /// Whether the URL should always include the hostname and application path root. /// If this is false (default), the URL maybe either full (such as http://vocadb.net/Album/CoverPicture/123) /// or relative (such as /Album/CoverPicture/123). /// Usually this should be set to true if the image is to be referred from another domain. /// </param> /// <returns>URL to the image thumbnail.</returns> public static string ImageThumb(this UrlHelper urlHelper, IEntryImageInformation imageInfo, ImageSize size, bool fullUrl = false) { if (imageInfo == null) return null; var shouldExist = ShouldExist(imageInfo); string dynamicUrl = null; // Use MVC dynamic actions when requesting original or an image that doesn't exist on disk. if (imageInfo.EntryType == EntryType.Album) { if (size == ImageSize.Original) dynamicUrl = urlHelper.Action("CoverPicture", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); else if (shouldExist && !imagePersister.HasImage(imageInfo, size)) dynamicUrl = urlHelper.Action("CoverPictureThumb", "Album", new { id = imageInfo.Id, v = imageInfo.Version }); } else if (imageInfo.EntryType == EntryType.Artist) { if (size == ImageSize.Original) dynamicUrl = urlHelper.Action("Picture", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); else if (shouldExist && !imagePersister.HasImage(imageInfo, size)) dynamicUrl = urlHelper.Action("PictureThumb", "Artist", new { id = imageInfo.Id, v = imageInfo.Version }); } if (dynamicUrl != null) { return (fullUrl ? AppConfig.HostAddress + dynamicUrl : dynamicUrl); } if (!shouldExist) return GetUnknownImageUrl(urlHelper, imageInfo); return imagePersister.GetUrlAbsolute(imageInfo, size, WebHelper.IsSSL(HttpContext.Current.Request)); }
public static string Artwork(this UrlHelper helper, WebMediaType mediaType, string id, string protocol = null, string hostName = null) { switch (mediaType) { case WebMediaType.Movie: return helper.Action("Cover", "MovieLibrary", new RouteValueDictionary(new { movie = id }), protocol, hostName); case WebMediaType.MusicAlbum: return helper.Action("AlbumImage", "MusicLibrary", new RouteValueDictionary(new { album = id }), protocol, hostName); case WebMediaType.MusicArtist: return helper.Action("ArtistImage", "MusicLibrary", new RouteValueDictionary(new { artist = id }), protocol, hostName); case WebMediaType.MusicTrack: return helper.Action("TrackImage", "MusicLibrary", new RouteValueDictionary(new { track = id }), protocol, hostName); case WebMediaType.Radio: case WebMediaType.TV: return helper.Action("ChannelLogo", "Television", new RouteValueDictionary(new { channelId = id }), protocol, hostName); case WebMediaType.Recording: // TODO: Make width configurable with a parameter (object attributes or something like it) return helper.Action("PreviewImage", "Recording", new RouteValueDictionary(new { id = id, width = 640 }), protocol, hostName); case WebMediaType.TVEpisode: return helper.Action("EpisodeImage", "TVShowsLibrary", new RouteValueDictionary(new { episode = id }), protocol, hostName); case WebMediaType.TVSeason: return helper.Action("SeasonImage", "TVShowsLibrary", new RouteValueDictionary(new { season = id }), protocol, hostName); case WebMediaType.TVShow: return helper.Action("SeriesPoster", "TVShowsLibrary", new RouteValueDictionary(new { season = id }), protocol, hostName); default: return String.Empty; } }
/// <summary> /// Renders editor for the specified page content item. /// </summary> public static MvcHtmlString EditorFor(this HtmlHelper html, PageContentModel content) { var settings = PageContentSerializer.Deserialize<PageContentDescription>(content.Settings); // if action or controller is not specified we will show default content editor if (string.IsNullOrWhiteSpace(settings.Edit.Action) || string.IsNullOrWhiteSpace(settings.Edit.Controller)) { return html.Action("DefaultContentEditor", "Page", new {settings}); } return html.Action(settings.Edit.Action, settings.Edit.Controller, new {content = content.Content, pageContentModel = content}); }
public static string AbsoluteAction(this UrlHelper helper, string action, string controller, object routeValues = null) { var requestUri = helper.RequestContext.HttpContext.Request.Url; string actionUrl = (routeValues == null) ? helper.Action(action, controller) : helper.Action(action, controller, routeValues); return string.Format("{0}://{1}{2}", requestUri.Scheme, requestUri.Authority, actionUrl); }
public static string CreateSortLink(this UrlHelper url, string action, string columnName) { string result = ""; //read the current request to see if there's a sort value string currentDirection = url.RequestContext.HttpContext.Request.QueryString["dir"]; string currentSort = url.RequestContext.HttpContext.Request.QueryString["s"]; if (string.IsNullOrEmpty(currentDirection) &! string.IsNullOrEmpty(currentSort)) { result = url.Action(action, new { s = columnName, dir = "desc" }); } else { result = url.Action(action, new { s = columnName}); } return result; }
public static string AbsoluteAction(this UrlHelper url, string action, string controller, object routeValues = null) { var request = url.RequestContext.HttpContext.Request; var actionUrl = url.Action(action, controller, routeValues, request.Url.Scheme); var relativeUri = url.ToRelativeUri(actionUrl); return url.ToPublicUrl(relativeUri); }
public static string NewsLink(this UrlHelper helper, News news) { if(string.IsNullOrEmpty(news.UrlKey)){ return helper.Action("ViewNewsById", "Content", new {id=news.NewsID, area="Content"}); } return helper.RouteUrl("News-View-Route", new { category = news.Category.StaticName, area = "Content" , news=news.UrlKey}); }
public static HtmlString RenderDocTypeGridEditorItem(this HtmlHelper helper, IPublishedContent content, string viewPath = "", string actionName = "", object model = null) { if (content == null) return new HtmlString(string.Empty); var controllerName = content.DocumentTypeAlias + "Surface"; if (!string.IsNullOrWhiteSpace(viewPath)) viewPath = viewPath.TrimEnd('/') + "/"; if (string.IsNullOrWhiteSpace(actionName)) actionName = content.DocumentTypeAlias; var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); if (umbracoHelper.SurfaceControllerExists(controllerName, actionName, true)) { return helper.Action(actionName, controllerName, new { dtgeModel = model ?? content, dtgeViewPath = viewPath }); } if (!string.IsNullOrWhiteSpace(viewPath)) return helper.Partial(viewPath + content.DocumentTypeAlias + ".cshtml", content); return helper.Partial(content.DocumentTypeAlias, content); }
public static string ActionUrl(this UrlHelper helper, string area, string controller, string action, object routeValues = null) { var rVals = routeValues == null ? new RouteValueDictionary() : new RouteValueDictionary(routeValues); if (area != null) rVals["area"] = area; return helper.Action(action, controller, rVals); }
/// <summary> /// Generates a fully qualified URL to an action method by using /// the specified action name, controller name and route values. /// </summary> /// <param name="url">The URL helper.</param> /// <param name="actionName">The name of the action method.</param> /// <param name="controllerName">The name of the controller.</param> /// <param name="routeValues">The route values.</param> /// <returns>The absolute URL.</returns> public static string AbsoluteAction(this UrlHelper url, string actionName, string controllerName, object routeValues = null) { string scheme = url.RequestContext.HttpContext.Request.Url.Scheme; return url.Action(actionName, controllerName, routeValues, scheme); }
public static MvcHtmlString DisplayWidgets(this HtmlHelper htmlHelper, string widgetLocation) { return htmlHelper.Action("WidgetDisplay", "Widget", new RouteValueDictionary() { {"widgetLocation", widgetLocation} }); }
public static string HotelEdit(this UrlHelper urlHelper, HotelPart hotelPart) { return urlHelper.Action( "Edit", "HotelAdmin", new { destinationId = hotelPart.DestinationPart.Id, hotelId = hotelPart.Id, area = "Summit.Core" }); }
public static string GenerateLink( this IUrlHelper urlHelper, LinkGenerationTestContext linkGenerationTestContext, ControllerTestContext controllerTestContext) { string uri = null; if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.Location)) { uri = linkGenerationTestContext.Location; } else if (!string.IsNullOrWhiteSpace(linkGenerationTestContext.RouteName)) { uri = urlHelper.RouteUrl( linkGenerationTestContext.RouteName, linkGenerationTestContext.RouteValues); } else { linkGenerationTestContext.Action = linkGenerationTestContext.Action ?? controllerTestContext.RouteData.Values["action"] as string ?? controllerTestContext.ActionName; linkGenerationTestContext.Controller = linkGenerationTestContext.Controller ?? controllerTestContext.RouteData.Values["controller"] as string ?? controllerTestContext.ControllerContext.ActionDescriptor.ControllerName; uri = urlHelper.Action( linkGenerationTestContext.Action, linkGenerationTestContext.Controller, linkGenerationTestContext.RouteValues); } return uri; }
public static MvcHtmlString CommentsCount(this HtmlHelper helper, string navigateUrl, string threadKey, string threadType, bool? allowComments = null) { if (SystemManager.GetModule("Comments") == null || string.IsNullOrEmpty(threadKey)) return MvcHtmlString.Empty; if (string.IsNullOrEmpty(navigateUrl)) { navigateUrl = "#comments-" + threadKey; } var controllerName = threadKey.EndsWith(ReviewsSuffix, StringComparison.Ordinal) ? CommentsHelpers.ReviewsControllerName : CommentsHelpers.CommentsControllerName; MvcHtmlString result; try { result = helper.Action(CommentsHelpers.CountActionName, controllerName, new { NavigateUrl = navigateUrl, ThreadKey = threadKey, ThreadType = threadType, AllowComments = allowComments }); } catch (HttpException) { result = MvcHtmlString.Empty; } catch (NullReferenceException) { //// Telerik.Sitefinity.Mvc.SitefinityMvcRoute GetOrderedParameters() on line 116 controllerType.GetMethods() throws null reference exception (controllerType is null). result = MvcHtmlString.Empty; } return result; }
public static string AbsoluteAction(this UrlHelper urlHelper, String actionName, String controllerName = null, Object routeValues = null) { var url = urlHelper.RequestContext.HttpContext.Request.Url; var scheme = (url != null) ? url.Scheme : "http"; return urlHelper.Action(actionName, controllerName, routeValues, scheme); }
/// <summary> /// Create the html required to make a link for a callstack line for a crash. /// </summary> /// <param name="Helper">The Url helper object.</param> /// <param name="CallStack">A line of a callstack to wrap in a link.</param> /// <param name="Model">The view model for the current page.</param> /// <returns>A string suitable for MVC to render.</returns> public static MvcHtmlString CallStackSearchLink( this UrlHelper Helper, string CallStack, CrashesViewModel Model ) { StringBuilder Result = new StringBuilder(); TagBuilder Tag = new TagBuilder( "a" ); string URL = Helper.Action( "Index", new { controller = "Crashes", SortTerm = Model.SortTerm, SortOrder = Model.SortOrder, CrashType = Model.CrashType, UserGroup = Model.UserGroup, SearchQuery = CallStack, UsernameQuery = Model.UsernameQuery, EpicIdQuery = Model.EpicIdQuery, MachineIdQuery = Model.MachineIdQuery, DescriptionQuery = Model.DescriptionQuery, MessageQuery = Model.MessageQuery, JiraQuery = Model.JiraQuery, DateFrom = Model.DateFrom, DateTo = Model.DateTo, BranchName = Model.BranchName, GameName = Model.GameName } ); Tag.MergeAttribute( "href", URL ); Tag.InnerHtml = CallStack; Result.AppendLine( Tag.ToString() ); return MvcHtmlString.Create( Result.ToString() ); }
public static string ActionAbsolute(this UrlHelper @this, [AspMvcAction] string actionName) { var isHttps = !DebugConfig.IsDebug || @this.RequestContext.HttpContext.Request.IsSecureConnection; var uriBuilder = new UriBuilder(@this.Action(actionName, "" + @this.RequestContext.RouteData.Values["controller"], new { }, isHttps ? "https" : "http")); ChangeUrlParams(uriBuilder); return uriBuilder.ToString(); }
public static HtmlString ActionLinkWithArray(this UrlHelper url, [AspMvcAction] string action, [AspMvcController] string controller, object routeData) { string href = url.Action(action, controller, new {area = ""}); var rv = new RouteValueDictionary(routeData); var parameters = new List<string>(); if (routeData != null) { foreach (var key in rv.Keys) { var propertyInfo = routeData.GetType().GetProperty(key); var value = propertyInfo.GetValue(routeData, null); var array = value as IEnumerable; if (array != null && !(array is string)) { foreach (string val in array) { parameters.Add(string.Format("{0}={1}", key, val)); } } else { parameters.Add(string.Format("{0}={1}", key, value)); } } } string paramString = string.Join("&", parameters.ToArray()); if (!string.IsNullOrEmpty(paramString)) { href += "?" + paramString; } return new HtmlString(href); }
public static string Home(this UrlHelper urlHelper, bool absoluteUrl = false) { if (absoluteUrl) return urlHelper.ActionAbsolute("Home", "Index"); return urlHelper.Action("Index", "Home"); }
public static HtmlString RenderMortarItem( this HtmlHelper helper, MortarRow row, MortarItem item, string viewPath = "", string actionName = "", object model = null) { if (item == null || item.Value == null) return new HtmlString(string.Empty); if (!string.IsNullOrWhiteSpace(viewPath)) viewPath = viewPath.TrimEnd('/') + "/"; if (string.IsNullOrWhiteSpace(actionName)) actionName = item.Value.DocumentTypeAlias; var controllerName = string.Concat(item.Value.DocumentTypeAlias, "Surface"); if (SurfaceControllerHelper.SurfaceControllerExists(controllerName, actionName, true)) { return helper.Action(actionName, controllerName, new { mortarModel = model ?? item.Value, mortarRow = row, mortarViewPath = viewPath }); } return helper.Partial(viewPath + item.Value.DocumentTypeAlias, model ?? item.Value); }
public static string SubdomainAction(this UrlHelper urlHelper, string actionName, string controllerName, object routeValues) { string baseUrl = GetDomainBase(urlHelper, null, actionName, controllerName, new RouteValueDictionary(routeValues)); return BuildUri(baseUrl, urlHelper.Action(actionName, controllerName, routeValues)); }
public static string Series(this UrlHelper helper, int seriesId, string seriesSlug) { return helper.Action( MVC.Posts.ActionNames.Series, MVC.Posts.Name, new { seriesId, seriesSlug }); }
public static string AbsoluteUrl(this UrlHelper url, string actionName, string controllerName, object routeValues = null) { if (url.RequestContext.HttpContext.Request.Url == null) return null; var schema = url.RequestContext.HttpContext.Request.Url.Scheme; return url.Action(actionName, controllerName, routeValues, schema); }
public static string SubdomainAction(this UrlHelper urlHelper, string actionName, string controllerName, string areaName = "") { var routeValues = new RouteValueDictionary { { "area", areaName } }; string baseUrl = GetDomainBase(urlHelper, null, actionName, controllerName, routeValues); return BuildUri(baseUrl, urlHelper.Action(actionName, controllerName, routeValues)); }
public static string Post(this UrlHelper helper, int id, string slug) { return helper.Action(MVC.PostDetails.ActionNames.Details, MVC.PostDetails.Name, new { id, slug }); }
/// <summary> /// Gets a URL to the specified blog post /// </summary> /// <param name="urlHelper">The URL helper.</param> /// <param name="post">Blog post to link to</param> /// <returns>URL to this blog post</returns> public static string BlogPost(this UrlHelper urlHelper, PostSummaryModel post) { // Post date needs to be padded with a 0 (eg. "01" for January) - T4MVC doesn't work in this // case because it's strongly-typed (can't pass a string for an int param) //return urlHelper.Action(MVC.Blog.View(post.Date.Month, post.Date.Year, post.Slug)); return urlHelper.Action("View", "Blog", new { month = post.Date.Month.ToString("00"), year = post.Date.Year, slug = post.Slug, area = string.Empty }); }
public static string AbsoluteAction(this UrlHelper url, string action, string controller, object routeValues) { Uri requestUrl = url.RequestContext.HttpContext.Request.Url; string absoluteAction = string.Format("{0}{1}", requestUrl.GetLeftPart(UriPartial.Authority), url.Action(action, controller, routeValues)); return absoluteAction; }
public static string AbsoluteAction(this UrlHelper urlHelper, ActionResult action) { var requestUrl = urlHelper.RequestContext.HttpContext.Request.Url; if (requestUrl == null) throw new InvalidOperationException("HttpRequest.Url was unexpectedly null."); var actionUrl = urlHelper.Action(action); return string.Format("{0}://{1}{2}", requestUrl.Scheme, requestUrl.Authority, actionUrl); }
public static string Calendar(this UrlHelper urlHelper, CalendarPart calendarPart) { var ap = calendarPart.ContentItem.Get(typeof (AutoroutePart)) as AutoroutePart; return ap != null && !string.IsNullOrWhiteSpace(ap.Path) ? "/" + ap.Path : urlHelper.Action("Item", "Calendar", new { calendarId = calendarPart.Identifier, area = "Orchard.CalendarEvents" }); }
public static string PackageList(this UrlHelper url, int page, string q) { return url.Action("ListPackages", "Packages", new { q, page }); }