Created
September 9, 2015 07:42
-
-
Save serbrech/84ab8c88791b1519d939 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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