本文整理汇总了C#中this.Content方法的典型用法代码示例。如果您正苦于以下问题:C# this.Content方法的具体用法?C# this.Content怎么用?C# this.Content使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.Content方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TranslateSystemUrl
public static string TranslateSystemUrl(this UrlHelper urlHelper, string url, string defaultBaseUrl = null)
{
if (String.IsNullOrWhiteSpace(url))
return null;
url = url.Trim();
if (url.Contains("://"))
{
return url;
}
else if (url.StartsWith("//"))
{
return String.Format("{0}:{1}", urlHelper.RequestContext.HttpContext.Request.Url.Scheme, url);
}
else if (!url.StartsWith("~") && !url.StartsWith("/") && !String.IsNullOrWhiteSpace(defaultBaseUrl))
{
defaultBaseUrl = defaultBaseUrl.TrimEnd('/');
if (defaultBaseUrl.Contains("://"))
{
return defaultBaseUrl + "/" + url;
}
else if (defaultBaseUrl.StartsWith("//"))
{
return String.Format("{0}:{1}/{2}", urlHelper.RequestContext.HttpContext.Request.Url.Scheme, defaultBaseUrl, url);
}
return urlHelper.Content(defaultBaseUrl + "/" + url);
}
return urlHelper.Content(url);
}
示例2: LessCss
public static HtmlString LessCss(this UrlHelper helper, string lessJsPath, params string[] cssFiles)
{
var html = new StringBuilder();
var useClientside = false;
var lessLinkTagFormat = @"<link rel=""stylesheet/less"" type=""text/css"" href=""{0}"">";
var cssLinkTagFormat = @"<link rel=""stylesheet"" type=""text/css"" href=""{0}"">";
#if DEBUG
useClientside = true;
#endif
foreach (var css in cssFiles)
{
if (!css.EndsWith(".less"))
html.AppendFormat(cssLinkTagFormat, helper.Content(css));
else if( useClientside )
html.AppendFormat(lessLinkTagFormat, helper.Content(css));
else
html.AppendFormat(cssLinkTagFormat, helper.Content(TranslateToCss(css)));
}
if (useClientside)
html.AppendFormat(@"<script src=""{0}"" type=""text/javascript""></script>", helper.Content(lessJsPath));
return new HtmlString(html.ToString());
}
示例3: AvatarUrl
public static string AvatarUrl(this UrlHelper urlHelper, string avatarIdentifier)
{
if (string.IsNullOrEmpty(avatarIdentifier))
return urlHelper.Content("~/content/img/avatar.jpg");
return urlHelper.Content("~/avatar/" + avatarIdentifier);
}
示例4: Css
/// <summary>
/// Retrieves a CSS link based on a themes path
/// </summary>
/// <param name="urlHelper"></param>
/// <param name="cssFile"></param>
/// <param name="theme"></param>
/// <returns></returns>
public static string Css(this UrlHelper urlHelper, string cssFile, string theme = null)
{
object oTheme = urlHelper.RequestContext.HttpContext.Session["Theme"];
if (oTheme != null)
theme = oTheme as string;
string url = null;
if (string.IsNullOrEmpty(theme))
url = urlHelper.Content("~/css/" + cssFile);
else
{
string lowerCssFile = cssFile.ToLower();
theme=theme.ToLower();
string key = theme + "|" + cssFile;
if (CssFileCache.ContainsKey(key))
return CssFileCache[key];
foreach (string path in CssPaths)
{
string webPath = string.Format(path, cssFile, theme);
if (File.Exists(urlHelper.RequestContext.HttpContext.Server.MapPath(webPath)))
{
url = urlHelper.Content(webPath);
CssFileCache.Add(key, url);
break;
}
}
}
return url;
}
示例5: ImageProduct
public static string ImageProduct(this UrlHelper urlHelper, string imageName)
{
if (string.IsNullOrEmpty(imageName))
{
return urlHelper.Content("~/Contents/Images/image.jpg");
}
return urlHelper.Content("~/Contents/Images/Product/" + imageName);
}
示例6: GetPhotoUrl
public static string GetPhotoUrl(this UrlHelper helper, string imageId, string size, string defaultUrl = null)
{
var photo = PhotoManager.Provider.GetPhotoResize(imageId, size);
if (photo != null)
{
return helper.Content(photo.Url);
}
return defaultUrl != null ? helper.Content(defaultUrl) : "";
}
示例7: Content
public static string Content(this System.Web.Mvc.UrlHelper Url, string Path, bool addTimeStamp)
{
if (!addTimeStamp)
return Url.Content(Path);
string serverPath = HttpContext.Current.Server.MapPath(Path);
DateTime lastWrite = File.GetLastWriteTimeUtc(serverPath);
string result = lastWrite.Ticks.ToString();
return Url.Content(Path) + "?t=" + result;
}
示例8: Content
public static string Content(this UrlHelper url, string contentPath, bool absolute)
{
Uri requestUrl = url.RequestContext.HttpContext.Request.Url;
if (absolute)
{
string absoluteAction = "{0}://{1}{2}".FormatWith(requestUrl.Scheme, requestUrl.Authority, url.Content(contentPath));
return absoluteAction;
}
return url.Content(contentPath);
}
示例9: BootstrapJS
/// <summary>
/// Provides a Javascript script tag for the Bootstrap framework.
/// </summary>
public static MvcHtmlString BootstrapJS(this UrlHelper helper)
{
string bootStrapPath = helper.Content("~/Assets/bootstrap/js/bootstrap.min.js");
string respondPath = helper.Content("~/Assets/bootstrap/js/respond.min.js");
string html = string.Format("<script type=\"text/javascript\" language=\"javascript\" src=\"{0}?version={1}\"></script>", bootStrapPath, ApplicationSettings.ProductVersion);
html += string.Format("\n<script type=\"text/javascript\" language=\"javascript\" src=\"{0}?version={1}\"></script>", respondPath, ApplicationSettings.ProductVersion);
return MvcHtmlString.Create(html);
}
示例10: Script
public static string Script(this UrlHelper helper, string file)
{
if (Config.ActiveConfiguration.MinifyFiles)
{
return helper.Content(String.Format("~/Content/{0}/{1}.min.js", ContentDirectory.script.ToString(), file));
}
else
{
return helper.Content(String.Format("~/Content/{0}/{1}.js", ContentDirectory.script.ToString(), file));
}
}
示例11: Image
public static string Image(this UrlHelper urlHelper, string imageName)
{
if (imageName == "Banner")
{
return urlHelper.Content("~/Contents/Images/Banner.JPG");
}
else if(string.IsNullOrEmpty(imageName))
{
return urlHelper.Content("~/Contents/Images/image.jpg");
}
return urlHelper.Content("~/Contents/Images/" + imageName);
}
示例12: Image
public static string Image(this UrlHelper url, string imageName)
{
string path = ConfigurationManager.AppSettings["ImagePath"];
if (string.IsNullOrWhiteSpace(path))
path = "~/Content/Images";
if (string.IsNullOrWhiteSpace(imageName))
return url.Content(path);
return url.Content(String.Format("{0}/{1}", path, imageName));
}
示例13: CssLink
/// <summary>
/// Provides a CSS link tag for the CSS file provided. If the relative path does not begin with ~ then
/// the Assets/Css folder is assumed.
/// </summary>
public static MvcHtmlString CssLink(this UrlHelper helper, string relativePath)
{
if (!relativePath.StartsWith("~"))
relativePath = "~/Assets/CSS/" + relativePath;
return MvcHtmlString.Create("<link href=\"" + helper.Content(relativePath) + "\" rel=\"stylesheet\" type=\"text/css\" />");
}
示例14: Script
public static string Script(this UrlHelper urlHelper, string fileName)
{
if (!fileName.EndsWith(".js"))
fileName += ".js";
return urlHelper.Content(string.Format("~/Content/{0}/{1}?version={2}", ScriptDir, fileName, RevisionNumber));
}
示例15: ContentVersioned
public static string ContentVersioned(this UrlHelper urlHelper, string contentPath)
{
string url = urlHelper.Content(contentPath);
int revisionNumber = GetRevisionNumber();
return String.Format("{0}?v={1}", url, revisionNumber);
}