Skip to content

Instantly share code, notes, and snippets.

@Zaidos
Created November 17, 2011 00:02
Show Gist options
  • Save Zaidos/1371940 to your computer and use it in GitHub Desktop.
Save Zaidos/1371940 to your computer and use it in GitHub Desktop.
Url Helper
using System.Web.Mvc;
/// <summary>
/// URL Extension Class
/// </summary>
public static class Url
{
/// <summary>
/// Returns a relative URL to Home.
/// </summary>
/// <param name="helper">UrlHelper</param>
/// <returns>Home content path.</returns>
public static string Home(this UrlHelper helper)
{
return helper.Content("~/");
}
/// <summary>
/// Returns a relative URL to an image.
/// </summary>
/// <param name="helper">UrlHelper</param>
/// <param name="fileName">File name.</param>
/// <returns>Image content path.</returns>
public static string Image(this UrlHelper helper, string fileName)
{
return helper.Content(contentPath: "~/Content/Images/" + fileName);
}
/// <summary>
/// Returns a relative URL to a style sheet.
/// </summary>
/// <param name="helper">UrlHelper</param>
/// <param name="fileName">File Name.</param>
/// <returns>Style content path.</returns>
public static string Style(this UrlHelper helper, string fileName)
{
return helper.Content(contentPath: "~/Content/CSS/" + fileName);
}
/// <summary>
/// Returns a relative URL to a script.
/// </summary>
/// <param name="helper">UrlHelper</param>
/// <param name="fileName">File name.</param>
/// <returns>Script content path.</returns>
public static string Script(this UrlHelper helper, string fileName)
{
return helper.Content(contentPath: "~/Scripts/" + fileName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment