Skip to content

Instantly share code, notes, and snippets.

@serbrech
Created September 9, 2015 07:42
Show Gist options
  • Save serbrech/84ab8c88791b1519d939 to your computer and use it in GitHub Desktop.
Save serbrech/84ab8c88791b1519d939 to your computer and use it in GitHub Desktop.
public static MvcHtmlString CompassUrl(this HtmlHelper helper, string compassUrl)
{
//...
var anchorBuilder = new TagBuilder("a");
anchorBuilder.Attributes.Add("target", IsCompassContext(helper) ? "_parent" : "_blank");
anchorBuilder.Attributes.Add("href", compassUrl);
//...
}
private static bool IsCompassContext(HtmlHelper helper)
{
var context = (helper.ViewContext.HttpContext.ApplicationInstance).Request.Params["context"];
// if in Compass, make the hyperlink redirect the parent page instead of opening a new blank page
return context != null && context.ToLower() == "compass";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment