public static MvcHtmlString Link(this HtmlHelper self, string linkText, AppLocalUrl location, object htmlAttributes = null) { var uri = location.Resolved(self.ViewContext.HttpContext); if (String.IsNullOrEmpty(linkText)) { throw new ArgumentException("Link text not allowed to be null or empty", "linkText"); } var tagBuilder = new TagBuilder("a") { InnerHtml = (!String.IsNullOrEmpty(linkText)) ? HttpUtility.HtmlEncode(linkText) : String.Empty }; if (htmlAttributes != null) { var attributeDictionary = (htmlAttributes as IDictionary <string, object>) ?? HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); tagBuilder.MergeAttributes(attributeDictionary); } tagBuilder.MergeAttribute("href", uri); var linkString = tagBuilder.ToString(TagRenderMode.Normal); return(MvcHtmlString.Create(linkString)); }
public static MvcForm BeginForm(this HtmlHelper self, AppLocalUrl location, FormMethod method = FormMethod.Post, object htmlAttributes = null) { var viewContext = self.ViewContext; var actionUri = location.Resolved(viewContext.HttpContext); var tagBuilder = new TagBuilder("form"); if (htmlAttributes != null) { var attributeDictionary = (htmlAttributes as IDictionary <string, object>) ?? HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); tagBuilder.MergeAttributes(attributeDictionary); } // action is implicitly generated, so htmlAttributes take precedence. tagBuilder.MergeAttribute("action", actionUri); // method is an explicit parameter, so it takes precedence over the htmlAttributes. tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true); bool traditionalJavascriptEnabled = viewContext.ClientValidationEnabled && !viewContext.UnobtrusiveJavaScriptEnabled; if (traditionalJavascriptEnabled) { // forms must have an ID for client validation tagBuilder.GenerateId(GetFormIdGenerator(viewContext)); } viewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag)); var form = new MvcForm(viewContext); if (traditionalJavascriptEnabled) { viewContext.FormContext.FormId = tagBuilder.Attributes["id"]; } return(form); }
public static string Of(this UrlHelper self, AppLocalUrl location) { return(location.Resolved(self.RequestContext.HttpContext)); }
public static ActionResult RedirectTo(this ControllerBase self, AppLocalUrl location, bool permanent = false) { var uri = location.Resolved(self.ControllerContext.HttpContext); return(new RedirectResult(uri, permanent)); }
public static ActionResult RedirectTo(this ControllerBase self, AppLocalUrl location, bool permanent = false) { var uri = location.Resolved(self.ControllerContext.HttpContext); return new RedirectResult(uri, permanent); }
public UrlPattern(string pattern) : base(0, pattern) { this.url = new AppLocalUrl(pattern); }
/// <summary> /// Creates a first class 'link' object (okay really a key-value-pair of a string and a URL). /// This can be useful if, for example, you need to pass a collection of links to your view. /// </summary> /// <param name="linkText">The (plain) text of the link</param> /// <param name="location">The destination of the link</param> /// <returns>Pair of: text and URL</returns> public static KeyValuePair <string, AppLocalUrl> LinkTo(this string linkText, AppLocalUrl location) { return(new KeyValuePair <string, AppLocalUrl>(linkText, location)); }