public static MvcHtmlString ProductImage(this HtmlHelper helper, string rawFile, ImageSize size, bool noCaching, object htmlAttributes) { var imgSizeIndicator = System.Enum.GetName(typeof(ImageSize), size); var imgFile = UrlHelper.GenerateContentUrl(string.Format("~/Images/Products/{0}", rawFile), helper.ViewContext.HttpContext); TagBuilder tb = new TagBuilder("img"); if (noCaching) { tb.MergeAttribute("src", imgFile + "?" + new Random().NextDouble().ToString(CultureInfo.InvariantCulture)); } else { tb.MergeAttribute("src", imgFile); } tb.MergeAttribute("border", "0"); var sizeValue = 65; switch (size) { case ImageSize.Medium: sizeValue = 130; break; case ImageSize.Large: sizeValue = 195; break; default: break; } tb.MergeAttribute("width", sizeValue.ToString()); tb.MergeAttribute("height", sizeValue.ToString()); if (htmlAttributes != null) { IDictionary <string, object> additionAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); tb.MergeAttributes <string, object>(additionAttributes); } return(MvcHtmlString.Create(tb.ToString(TagRenderMode.SelfClosing))); }
public override void ExecuteResult(ControllerContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (context.IsChildAction) { throw new InvalidOperationException(MvcResources.RedirectAction_CannotRedirectInChildAction); } string destinationUrl = UrlHelper.GenerateContentUrl(Url, context.HttpContext); context.Controller.TempData.Keep(); if (Permanent) { context.HttpContext.Response.RedirectPermanent(destinationUrl, endResponse: false); } else { context.HttpContext.Response.Redirect(destinationUrl, endResponse: false); } }
public static string RootImagePath() { HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current); return(UrlHelper.GenerateContentUrl(CommonHelpers.Helpers.GetAppSetting(Literals.AppSettingKey_ImagePath), httpContext)); }
public static string ReturnImagePath() { HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current); return(UrlHelper.GenerateContentUrl("~/ImageFile/", httpContext)); }
public static HtmlString Image(this HtmlHelper helper, string fileName, string attributes) { fileName = string.Format("{0}", UrlHelper.GenerateContentUrl(VirtualImagePath(fileName), helper.ViewContext.HttpContext)); return(new HtmlString(string.Format(@"<img src=""{0}"" {1} />", helper.AttributeEncode(fileName), helper.AttributeEncode(attributes)))); }
public static HtmlString ImagePath(this HtmlHelper helper, string fileName) { return(new HtmlString(UrlHelper.GenerateContentUrl(VirtualImagePath(fileName), helper.ViewContext.HttpContext))); }
/// <summary> /// Renders the stylesheets onto the page that were added by the view and partial views. /// </summary> /// <param name="html">The HTMLHelper</param> /// <returns></returns> public static MvcHtmlString RenderStyleSheets(this HtmlHelper html) { var sb = new StringBuilder(); //Styles.Reverse(); foreach (var style in Styles.OrderBy(i => i.AssetHierarchy)) { sb.AppendLine(String.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\">", UrlHelper.GenerateContentUrl(style.Url, html.ViewContext.HttpContext))); } return(new MvcHtmlString(sb.ToString())); }
private static MvcHtmlString VersionedContent(this HtmlHelper html, string template, string contentPath) { contentPath = UrlHelper.GenerateContentUrl(contentPath, html.ViewContext.HttpContext) + "?v=" + VersionUtils.VersionNumber; return(MvcHtmlString.Create(string.Format(template, contentPath))); }