/// <summary> /// Write out a download link /// </summary> /// <param name="helper"></param> /// <param name="download">The download item to render</param> /// <returns></returns> public static MvcHtmlString Download(this HtmlHelper helper, Download download) { if (download == null || String.IsNullOrEmpty(download.Url)) { return null; } // TODO: this does not contain any XPM markup // TODO: configurize the mime type to Font Awesome mapping // filetypes supported by http://fortawesome.github.io/Font-Awesome/icons/#file-type var mimeTypes = new Dictionary<string, string> { {"application/ms-excel", "excel"}, {"application/pdf", "pdf"}, {"application/x-wav", "audio"}, {"audio/x-mpeg", "audio"}, {"application/msword", "word"}, {"text/rtf", "word"}, {"application/zip", "archive"}, {"image/gif", "image"}, {"image/jpeg", "image"}, {"image/png", "image"}, {"image/x-bmp", "image"}, {"text/plain", "text"}, {"text/css", "code"}, {"application/x-javascript", "code"}, {"application/ms-powerpoint", "powerpoint"}, {"video/vnd.rn-realmedia", "video"}, {"video/quicktime", "video"}, {"video/mpeg", "video"} }; string fileType = null; if (mimeTypes.ContainsKey(download.MimeType)) { fileType = mimeTypes[download.MimeType]; } string iconClass = (fileType == null ? "fa-file" : String.Format("fa-file-{0}-o", fileType)); string friendlyFileSize = helper.FriendlyFileSize(download.FileSize).ToString(); string descriptionHtml = (!String.IsNullOrEmpty(download.Description) ? String.Format("<small>{0}</small>", download.Description) : String.Empty); // TODO: use partial view instead of hardcoding HTML string downloadHtml = String.Format(@" <div class=""download-list""> <i class=""fa {0}""></i> <div> <a href=""{1}"">{2}</a> <small class=""size"">({3})</small> {4} </div> </div>", iconClass, download.Url, download.FileName, friendlyFileSize, descriptionHtml); return new MvcHtmlString(downloadHtml); }
public static MvcHtmlString Download(this HtmlHelper helper, Download download) { using (new Tracer(helper, download)) { if (download == null || string.IsNullOrEmpty(download.Url)) { return MvcHtmlString.Empty; } return new MvcHtmlString(download.ToHtml(null)); } }