public static MvcHtmlString MenuItemCheveron(this HtmlHelper htmlHelper, string text, string action, string controller, string cheveronText, string area = null) { var li = new TagBuilder("li"); var routeData = htmlHelper.ViewContext.RouteData; var currentAction = routeData.GetRequiredString("action"); var currentController = routeData.GetRequiredString("controller"); var currentArea = routeData.DataTokens["area"] as string; var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection); if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) && string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase) && string.Equals(currentArea, area, StringComparison.OrdinalIgnoreCase)) { li.AddCssClass("active"); } var linkBuilder = new TagBuilder("a"); linkBuilder.MergeAttribute("href", urlHelper.Action(action, controller)); var htmlText = li.ToString(TagRenderMode.StartTag); htmlText += linkBuilder.ToString(TagRenderMode.StartTag); htmlText += text; htmlText += linkBuilder.ToString(TagRenderMode.EndTag); htmlText += li.ToString(TagRenderMode.EndTag); return MvcHtmlString.Create(htmlText.ToString()); }
public static MvcHtmlString ActionImage(this HtmlHelper html, string action, string controllerName, object routeValues, string imagePath, string alt, string confirmMessage, bool newWindow) { var url = new UrlHelper(html.ViewContext.RequestContext); // build the <img> tag var imgBuilder = new TagBuilder("img"); imgBuilder.MergeAttribute("src", url.Content(imagePath)); imgBuilder.MergeAttribute("alt", alt); string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing); // build the <a> tag var anchorBuilder = new TagBuilder("a"); anchorBuilder.MergeAttribute("href", url.Action(action, controllerName, routeValues)); anchorBuilder.InnerHtml = imgHtml; // include the <img> tag inside if (!string.IsNullOrEmpty(confirmMessage)) anchorBuilder.MergeAttribute("onclick", "return confirm('" + confirmMessage + "')"); if (newWindow) anchorBuilder.MergeAttribute("target", "_blank"); string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal); return MvcHtmlString.Create(anchorHtml); }
public static MvcHtmlString ActionLinkImage(this HtmlHelper htmlHelper, string imageLocation, string altTag, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes) { var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection); var link = new TagBuilder("a"); link.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routeValues)); link.MergeAttribute("target", (string)htmlAttributes["target"]); htmlAttributes.Remove("target"); link.InnerHtml = htmlHelper.Image(imageLocation, altTag, htmlAttributes).ToString(); return MvcHtmlString.Create(link.ToString(TagRenderMode.Normal)); }
private async Task <BreadCrumbNode> GetContentItemNode(ContentItem item) { var metadataitem = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(item); return(new BreadCrumbNode { Title = item.DisplayText, Type = "breadcrumb-specific-content-item-" + item.ContentItemId, Id = item.ContentItemId.ToString(CultureInfo.InvariantCulture), Url = UrlHelper?.Action(metadataitem.EditorRouteValues["action"].ToString(), metadataitem.EditorRouteValues), // _url.ItemEditUrl(item), IsLeaf = !item.Has("ListPart") }); }
/// <summary> /// Creates the appropriate li and anchor tags for use inside of the skeleton tabs. /// </summary> /// <param name="this">Instance of HtmlHelper being extended.</param> /// <param name="tabText">The text displayed on the tab.</param> /// <param name="activeControllerName">Name of the active controller. This is used to determine which anchor tag in /// the tabs gets the 'active' css class.</param> /// <returns></returns> public static MvcHtmlString Tab(this HtmlHelper @this, string tabText, string activeControllerName) { var text = String.IsNullOrEmpty(tabText) ? "My Tasks" : tabText; var controllerName = String.IsNullOrEmpty(activeControllerName) ? "Tasks" : activeControllerName; var url = new UrlHelper(@this.ViewContext.RequestContext); var link = new Element("a").AddAttribute("href", url.Action("Index", controllerName)).Update(tabText); var currentController = @this.ViewContext.RequestContext.RouteData.Values["controller"].ToString(); if (controllerName.Equals(currentController, StringComparison.OrdinalIgnoreCase)) link.CssClasses.Add("active"); return MvcHtmlString.Create(new Element("li", link)); }
public static string ActionLinkSelected(this HtmlHelper htmlHelper, string linkText, string url, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes) { if (string.IsNullOrEmpty(linkText)) throw new ArgumentException("Value cannot be null or empty.", "linkText"); if (string.IsNullOrEmpty(url) || url == "/") url = "/default.aspx"; // Build the link var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection); var link = new TagBuilder("a"); link.InnerHtml = htmlHelper.Encode(linkText); link.MergeAttributes(htmlAttributes); link.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routeValues)); // Check to see if the link is to be selected if (htmlHelper.ViewContext.HttpContext.Request.RawUrl.StartsWith(url, StringComparison.OrdinalIgnoreCase)) link.AddCssClass("selected"); return link.ToString(TagRenderMode.Normal); }
private ApplicationPath GetKnowledgeArticleApplicationPath(OrganizationServiceContext context, Entity article) { article.AssertEntityName("knowledgearticle"); var number = article.GetAttributeValue <string>("articlepublicnumber"); if (string.IsNullOrEmpty(number)) { return(null); } var httpContext = HttpContext.Current; if (httpContext == null) { return(null); } var httpContextWrapper = new HttpContextWrapper(HttpContext.Current); var routeData = RouteTable.Routes.GetRouteData(httpContextWrapper); if (routeData == null) { return(null); } var urlHelper = new UrlHelper(new RequestContext(httpContextWrapper, routeData)); var languageLocaleCode = article.Contains("language_locale.code") ? article.GetAttributeValue <AliasedValue>("language_locale.code").Value as string : null; if (string.IsNullOrWhiteSpace(languageLocaleCode)) { var localeid = article.GetAttributeValue <EntityReference>("languagelocaleid"); if (localeid != null) { var locale = context.CreateQuery("languagelocale").FirstOrDefault(lang => lang.GetAttributeValue <Guid>("languagelocaleid") == localeid.Id); if (locale != null) { languageLocaleCode = locale.GetAttributeValue <string>("code"); } } } // If multi-language is enabled, return URL using in approriate multi-language URL format. var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo(); string url = string.Empty; if (contextLanguageInfo.IsCrmMultiLanguageEnabled && ContextLanguageInfo.DisplayLanguageCodeInUrl) { var actionUrl = urlHelper.Action("Article", "Article", new { number = number, area = "KnowledgeManagement" }); // if actionUrl is null, ex: deactivated root page. if (actionUrl == null) { return(null); } url = string.Format("{0}{1}", httpContext.Request.Url.GetLeftPart(UriPartial.Authority), actionUrl); url = contextLanguageInfo.FormatUrlWithLanguage(false, languageLocaleCode, new Uri(url)); } else { url = urlHelper.Action("Article", "Article", new { number = number, lang = languageLocaleCode, area = "KnowledgeManagement" }); } return(url == null ? null : ApplicationPath.FromAbsolutePath(url)); }
public IHtmlContent ActionLink(UrlHelper Url, dynamic Shape, object Value) { var RouteValues = (object)Shape.RouteValues; RouteValueDictionary rvd; if (RouteValues == null) { rvd = new RouteValueDictionary(); } else { rvd = RouteValues as RouteValueDictionary ?? new RouteValueDictionary(RouteValues); } var action = Url.Action((string)rvd["action"], (string)rvd["controller"], rvd); IEnumerable<string> classes = Shape.Classes; IDictionary<string, string> attributes = Shape.Attributes; attributes["href"] = action; string id = Shape.Id; var tag = Orchard.DisplayManagement.Shapes.Shape.GetTagBuilder("a", id, classes, attributes); tag.InnerHtml.Append(CoerceHtmlString(Value)); return tag; }
public void SendEmailDiffusionDialogueSecurite(DialogueSecurite dialogueSecurite) { Site site = db.Sites.First(s => s.SiteID == dialogueSecurite.SiteId); string to = GetEmailFor("DiffusionFicheSecurite", db.Sites.Find(dialogueSecurite.SiteId).Trigramme); UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext); string urlToDialogueSecurite = url.Action("Edit", "DialogueSecurite", new System.Web.Routing.RouteValueDictionary(new { id = dialogueSecurite.Id }), "http", HttpContext.Current.Request.Url.Host); MailAddress from = new MailAddress("*****@*****.**"); //Contournement, je n'arrive pas à charger les objets "lieu" dans le "DialogueSecurite", alors que l'ID est bien présent ... Lieu lieu = db.Lieux.Find(dialogueSecurite.LieuId); Zone zone = db.Zones.Find(dialogueSecurite.ZoneId); string subject = "Nouveau Dialogue Sécurité " + dialogueSecurite.Code; string body = "<div style='font-family: Verdana, sans-serif;'><H2 style='background-color:#FD9910;color:#FFFFFF;text-align:center;border-radius: 25px;'>Le Dialogue Sécurité " + dialogueSecurite.Code + " vient d'être diffusé.</H2></div>" + "<br/>" + "<table><tbody>"; body += "<tr><td>Dialogués : </td><td>1 / </td><td>" + dialogueSecurite.Entretenu1.Prenom + "</td><td>" + dialogueSecurite.Entretenu1.Nom + "</td><td> du service : </td><td>" + dialogueSecurite.ServiceType3.Nom + "</td></tr>"; if (dialogueSecurite.Entretenu2.Nom != null) { body += "<tr><td></td><td>2 / </td><td>" + dialogueSecurite.Entretenu2.Prenom + "</td><td>" + dialogueSecurite.Entretenu2.Nom + "</td><td> du service : </td><td>" + dialogueSecurite.ServiceType4.Nom + "</td></tr>"; } if (dialogueSecurite.Entretenu3.Nom != null) { body += "<tr><td></td><td>3 / </td><td>" + dialogueSecurite.Entretenu3.Prenom + "</td><td>" + dialogueSecurite.Entretenu3.Nom + "</td><td> du service : </td><td>" + dialogueSecurite.ServiceType5.Nom + "</td></tr>"; } body += "<tr></tr>"; body += "<tr><td>Dialogueurs :</td><td>1 / </td><td>" + dialogueSecurite.Dialogueur1.Prenom + "</td><td>" + dialogueSecurite.Dialogueur1.Nom + "</td><td> du service : </td><td>" + dialogueSecurite.ServiceType.Nom + "</td></tr>"; if (dialogueSecurite.Dialogueur2.Nom != null) { body += "<tr><td></td><td>2 / </td><td>" + dialogueSecurite.Dialogueur2.Prenom + "</td><td>" + dialogueSecurite.Dialogueur2.Nom + "</td><td> du service : </td><td>" + dialogueSecurite.ServiceType1.Nom + "</td></tr>"; } if (dialogueSecurite.Dialogueur3.Nom != null) { body += "<tr><td></td><td>3 / </td><td>" + dialogueSecurite.Dialogueur3.Prenom + "</td><td>" + dialogueSecurite.Dialogueur3.Nom + "</td><td> du service : </td><td>" + dialogueSecurite.ServiceType2.Nom + "</td></tr>"; } body += "</tbody></table>"; body += "<br/>"; body += "<div> Thématique : " + dialogueSecurite.Thematique.Nom + "</div>"; body += "<br/>"; body += "<table><tbody>" + "<tr><td>SITUER</td><td>" + dialogueSecurite.Contexte + "</td></tr>" + "<tr><td>OBSERVER</td><td>" + dialogueSecurite.Observation + "</td></tr>" + "<tr><td>REFLECHIR</td><td>" + dialogueSecurite.Reflexion + "</td></tr>" + "<tr><td>AGIR</td><td>" + dialogueSecurite.Action + "</td></tr>" + "</table></tbody>"; body += "<br/>"; body += "<div> Zone : " + zone.ZoneType.Nom + "</div>"; body += "<div> Lieu : " + lieu.Nom + "</div>"; body += "<br/>"; body += "<div> Lien vers le dialogue : " + urlToDialogueSecurite + "</div>"; if (to != "" && to != null) { SendEmail(from, subject, body, to); } }
public static MvcHtmlString TabbedIconMenu(this HtmlHelper helper, IEnumerable <MenuTab> tabs, string menuId, string menuCssClass, bool singleController) { var route = helper.ViewContext.IsChildAction ? helper.ViewContext.ParentActionViewContext.RouteData : helper.ViewContext.RouteData; var controller = route.GetRequiredString("controller"); var action = route.GetRequiredString("action"); var urlHelper = new UrlHelper(helper.ViewContext.RequestContext); var ulTemplateFormat = "<ul id=\"{0}\" class=\"{1}\" >"; var liTemplateFormat = "<li><a href=\"{0}\" class=\"{1}\"><i class=\"{2}\"></i> {3}</a>"; var menuSb = new StringBuilder(); menuSb.AppendFormat(ulTemplateFormat, menuId, menuCssClass); var index = 0; foreach (var tab in tabs) { var first = index <= 0 ? "first" : string.Empty; if (!singleController) { if ((controller.ToLower() == tab.Controller.ToLower() && action.ToLower() == tab.Action.ToLower()) || controller.ToLower() == tab.Controller.ToLower()) { menuSb.AppendFormat( liTemplateFormat, urlHelper.Action( tab.Action.ToLowerInvariant(), tab.Controller, tab.RouteValues), "active " + first, tab.CssClass, tab.Text); } else { menuSb.AppendFormat( liTemplateFormat, urlHelper.Action( tab.Action.ToLowerInvariant(), tab.Controller, tab.RouteValues), " " + first, tab.CssClass, tab.Text); } } else { if ((controller.ToLower() == tab.Controller.ToLower() && action.ToLower() == tab.Action.ToLower())) { menuSb.AppendFormat( liTemplateFormat, urlHelper.Action( tab.Action.ToLowerInvariant(), tab.Controller, tab.RouteValues), "active " + first, tab.CssClass, tab.Text); } else { menuSb.AppendFormat( liTemplateFormat, urlHelper.Action( tab.Action.ToLowerInvariant(), tab.Controller, tab.RouteValues), " " + first, tab.CssClass, tab.Text); } } index++; } menuSb.Append("\n</ul>\n\n"); return(MvcHtmlString.Create(menuSb.ToString())); }
public static string ConfirmationUrl(this UrlHelper url, ActionResult actionResult, string username, string token, string protocol) { return(url.Action(actionResult.AddRouteValue("username", username).AddRouteValue("token", token), protocol: protocol)); }
public ActionResult CheckoutMethod(CheckoutPage currentPage) { var viewModel = new CheckoutMethodViewModel(currentPage, _urlHelper.Action("Index", "Checkout")); return(View("CheckoutMethod", viewModel)); }
/// <summary> /// Gets the current action URL. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="html">The HTML.</param> /// <returns></returns> public static string GetCurrentActionUrl <T>(HtmlHelper <T> html) { var url = new UrlHelper(html.ViewContext.RequestContext); return(url.Action(html.ViewContext.RouteData.GetRequiredString("action"))); }
public static string GetCurrentActionUrl(this WebViewPage page) { var url = new UrlHelper(page.ViewContext.RequestContext); return(url.Action(page.ViewContext.RouteData.GetRequiredString("action"))); }
public static string CancelUpload(this UrlHelper url) { return(url.Action(actionName: "CancelUpload", controllerName: "Packages")); }
public static string UndoPendingEdits(this UrlHelper url, IPackageVersionModel package) { return(url.Action(actionName: "UndoPendingEdits", controllerName: "Packages", routeValues: new { id = package.Id, version = package.Version })); }
public static string VerifyPackage(this UrlHelper url) { return(url.Action(actionName: "VerifyPackage", controllerName: "Packages")); }
public static string Register(this UrlHelper url) { return(url.Action(actionName: "LogOn", controllerName: "Authentication")); }
public static string ConfirmationRequired(this UrlHelper url) { return(url.Action("ConfirmationRequired", controllerName: "Users")); }
public static string ProductBrandIndexUrl(this UrlHelper helper, object routeValue = null, string controller = "productbrand", string action = "index") { return(helper.Action(action, controller, routeValue)); }
protected override void WriteHtmlCore(HtmlTextWriter writer) { var tab = base.Component; MoveSpecialTabToEnd(tab.Items); var hasContent = tab.Items.Any(x => x.Content != null || x.Ajax); var isTabbable = tab.Position != TabsPosition.Top; var isStacked = tab.Position == TabsPosition.Left || tab.Position == TabsPosition.Right; var urlHelper = new UrlHelper(this.ViewContext.RequestContext); if (tab.Items.Count == 0) { return; } tab.HtmlAttributes.AppendCssClass("tabbable"); if (isTabbable) { tab.HtmlAttributes.AppendCssClass("tabs-{0}".FormatInvariant(tab.Position.ToString().ToLower())); } if (tab.SmartTabSelection) { tab.HtmlAttributes.AppendCssClass("tabs-autoselect"); tab.HtmlAttributes.Add("data-tabselector-href", urlHelper.Action("SetSelectedTab", "Common", new { area = "admin" })); } if (isStacked) { tab.HtmlAttributes.AppendCssClass("row"); } if (tab.OnAjaxBegin.HasValue()) { tab.HtmlAttributes.Add("data-ajax-onbegin", tab.OnAjaxBegin); } if (tab.OnAjaxSuccess.HasValue()) { tab.HtmlAttributes.Add("data-ajax-onsuccess", tab.OnAjaxSuccess); } if (tab.OnAjaxFailure.HasValue()) { tab.HtmlAttributes.Add("data-ajax-onfailure", tab.OnAjaxFailure); } if (tab.OnAjaxComplete.HasValue()) { tab.HtmlAttributes.Add("data-ajax-oncomplete", tab.OnAjaxComplete); } if (tab.IsResponsive) { tab.HtmlAttributes.AppendCssClass("nav-responsive"); tab.HtmlAttributes.Add("data-breakpoint", tab.Breakpoint); } writer.AddAttributes(tab.HtmlAttributes); writer.RenderBeginTag("div"); // root div { if (tab.Position == TabsPosition.Below && hasContent) { RenderTabContent(writer); } if (isStacked) { writer.AddAttribute("class", "col-lg-auto nav-aside"); writer.RenderBeginTag("aside"); // opening left/right tabs col } // Tabs var ulAttrs = new Dictionary <string, object>(); ulAttrs.AppendCssClass("nav"); if (tab.Style == TabsStyle.Tabs) { ulAttrs.AppendCssClass("nav-tabs"); } else if (tab.Style == TabsStyle.Pills) { ulAttrs.AppendCssClass("nav-pills"); } else if (tab.Style == TabsStyle.Material) { ulAttrs.AppendCssClass("nav-tabs nav-tabs-line"); } if (tab.HideSingleItem && tab.Items.Count == 1) { ulAttrs.AppendCssClass("d-none"); } if (isStacked) { ulAttrs.AppendCssClass("flex-row flex-lg-column"); } writer.AddAttributes(ulAttrs); string selector = null; var loadedTabs = new List <string>(); writer.RenderBeginTag("ul"); { // enable smart tab selection if (tab.SmartTabSelection) { selector = TrySelectRememberedTab(); } int i = 1; foreach (var item in tab.Items) { var loadedTabName = this.RenderItemLink(writer, item, i); if (loadedTabName.HasValue()) { loadedTabs.Add(loadedTabName); } i++; } writer.RenderEndTag(); // ul } if (isStacked) { writer.RenderEndTag(); // closing left/right tabs col } // TODO: (mc) render right positioned tabs also if (tab.Position != TabsPosition.Below && hasContent) { if (isStacked) { writer.AddAttribute("class", "col-lg nav-content"); writer.RenderBeginTag("div"); // opening left/right content col } RenderTabContent(writer); if (isStacked) { writer.RenderEndTag(); // closing left/right content col } } if (selector != null) { writer.WriteLine( @"<script> $(function() {{ _.delay(function() {{ $(""{0}"").trigger(""show""); }}, 100); }}) </script>".FormatInvariant(selector)); } if (loadedTabs.Count > 0) { foreach (var tabName in loadedTabs) { writer.WriteLine("<input type='hidden' class='loaded-tab-name' name='LoadedTabs' value='{0}' />", tabName); } } writer.RenderEndTag(); // div.tabbable if (tab.IsResponsive /* && tab.TabContentHeaderContent != null*/) { writer.WriteLine(@"<script>$(function() {{ $('#{0}').responsiveNav(); }})</script>".FormatInvariant(tab.Id)); } } }
public static string ManagePackageOwners(this UrlHelper url, IPackageVersionModel package) { return(url.Action(MVC.Packages.ManagePackageOwners(package.Id, package.Version))); }
// <nav> // <ul class="pagination"> // <li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">«</span></a></li> // <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li> // <li><a href="#">2</a></li> // <li><a href="#">3</a></li> // <li><a href="#">4</a></li> // <li><a href="#">5</a></li> // <li><a href="#" aria-label="Next"><span aria-hidden="true">»</span></a></li> // </ul> //</nav> public static MvcHtmlString Pager(this HtmlHelper helper, int currentPage, int pageSize, int totalItemCount, object routeValues, string actionOveride = null, string controllerOveride = null) { // how many pages to display in each page group const var cGroupSize = ForumConfiguration.Instance.PagingGroupSize; var pageCount = (int)Math.Ceiling(totalItemCount / (double)pageSize); if (pageCount <= 0) { return(null); } // cleanup any out bounds page number passed currentPage = Math.Max(currentPage, 1); currentPage = Math.Min(currentPage, pageCount); var urlHelper = new UrlHelper(helper.ViewContext.RequestContext, helper.RouteCollection); var containerdiv = new TagBuilder("nav"); containerdiv.AddCssClass("pagination-post text-right"); var container = new TagBuilder("ul"); container.AddCssClass("pagination pagination-sm"); var actionName = !string.IsNullOrWhiteSpace(actionOveride) ? actionOveride : helper.ViewContext.RouteData.GetRequiredString("action"); var controllerName = !string.IsNullOrWhiteSpace(controllerOveride) ? controllerOveride : helper.ViewContext.RouteData.GetRequiredString("controller"); // calculate the last page group number starting from the current page // until we hit the next whole divisible number var lastGroupNumber = currentPage; while (lastGroupNumber % cGroupSize != 0) { lastGroupNumber++; } // correct if we went over the number of pages var groupEnd = Math.Min(lastGroupNumber, pageCount); // work out the first page group number, we use the lastGroupNumber instead of // groupEnd so that we don't include numbers from the previous group if we went // over the page count var groupStart = lastGroupNumber - (cGroupSize - 1); // if we are past the first page if (currentPage > 1) { var previousli = new TagBuilder("li"); var previous = new TagBuilder("a"); previous.SetInnerText("«"); previous.AddCssClass("previous"); var routingValues = new RouteValueDictionary(routeValues) { { "p", currentPage - 1 } }; previous.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routingValues)); previousli.InnerHtml = previous.ToString(); container.InnerHtml += previousli; } // if we have past the first page group if (currentPage > cGroupSize) { var previousDotsli = new TagBuilder("li"); var previousDots = new TagBuilder("a"); previousDots.SetInnerText("..."); previousDots.AddCssClass("previous-dots"); var routingValues = new RouteValueDictionary(routeValues) { { "p", groupStart - cGroupSize } }; previousDots.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routingValues)); previousDotsli.InnerHtml = previousDots.ToString(); container.InnerHtml += previousDotsli.ToString(); } for (var i = groupStart; i <= groupEnd; i++) { var pageNumberli = new TagBuilder("li"); pageNumberli.AddCssClass(i == currentPage ? "active" : "p"); var pageNumber = new TagBuilder("a"); pageNumber.SetInnerText(i.ToString()); var routingValues = new RouteValueDictionary(routeValues) { { "p", i } }; pageNumber.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routingValues)); pageNumberli.InnerHtml = pageNumber.ToString(); container.InnerHtml += pageNumberli.ToString(); } // if there are still pages past the end of this page group if (pageCount > groupEnd) { var nextDotsli = new TagBuilder("li"); var nextDots = new TagBuilder("a"); nextDots.SetInnerText("..."); nextDots.AddCssClass("next-dots"); var routingValues = new RouteValueDictionary(routeValues) { { "p", groupEnd + 1 } }; nextDots.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routingValues)); nextDotsli.InnerHtml = nextDots.ToString(); container.InnerHtml += nextDotsli.ToString(); } // if we still have pages left to show if (currentPage < pageCount) { var nextli = new TagBuilder("li"); var next = new TagBuilder("a"); next.SetInnerText("»"); next.AddCssClass("next"); var routingValues = new RouteValueDictionary(routeValues) { { "p", currentPage + 1 } }; next.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routingValues)); nextli.InnerHtml = next.ToString(); container.InnerHtml += nextli.ToString(); } containerdiv.InnerHtml = container.ToString(); return(MvcHtmlString.Create(containerdiv.ToString())); }
public override string GetUrl(UrlHelper url) { return(url.Action("Details", "News", new { year = DateCreate.Year, month = DateCreate.Month.ToString("00"), day = DateCreate.Day.ToString("00"), titleUrl = TitleUrl })); }
public void ToLogin(AuthorizationContext filterContext) { var url = new UrlHelper(filterContext.RequestContext); filterContext.Result = new RedirectResult(url.Action("Index", "Login")); }
public ActionResult formSubmit(Category model, string actionType) { List <string> errorMessage = new List <string>(); string successMessage = Resources.NotifResource.RequestSuccess; SessionForSP sessionParam = new SessionForSP(); sessionParam.OrganizationID = new Guid(Session["OrganizationID"].ToString()); sessionParam.BusinessUnitID = new Guid(Session["BusinessUnitID"].ToString()); sessionParam.CurrentUserID = new Guid(Session["CurrentUserID"].ToString()); if (ModelState.IsValid) { KeyValuePair <int, string> results = new KeyValuePair <int, string>(1, ""); model.ModifiedBy = new Guid(Session["CurrentUserID"].ToString()); if (actionType == "Create") { model.CategoryID = Guid.NewGuid(); results = db.Category_Insert(model, sessionParam); } else if (actionType == "Edit") { results = db.Category_Update(model); } else if (actionType == "ChangeStatus") { results = db.Category_ChangeStatus(model); } else if (actionType == "Delete") { results = db.Category_Delete(model); } if (results.Key == 0 || results.Key == 16 || results.Key == 6) { UrlHelper u = new UrlHelper(this.ControllerContext.RequestContext); string url = u.Action("Edit", "Category", new { id = model.CategoryID, success = successMessage }); string urlNew = u.Action("Create", "Category"); var jsonData = new { flag = true, Message = url, urlNew = urlNew }; return(Json(jsonData)); } else { var jsonData = new { flag = false, Message = results.Value.ToString() }; return(Json(jsonData)); } } else { foreach (var key in ModelState.Keys) { var error = ModelState[key].Errors.FirstOrDefault(); if (error != null) { errorMessage.Add(error.ErrorMessage); } } var jsonData = new { flag = false, Message = errorMessage.First() }; return(Json(jsonData)); } }
public static string VerifyPackage(this UrlHelper url) { return(url.Action(MVC.Packages.VerifyPackage())); }
/// <summary> /// Gets the URL of the file in the upload field with the given property alias on the given TypedEntity at the specific size /// </summary> /// <param name="url">The URL.</param> /// <param name="entity">The entity.</param> /// <param name="propertyAlias">The property alias.</param> /// <param name="size">The size (must be a prevalue on the upload property editor).</param> /// <returns></returns> public static string GetMediaUrl(this UrlHelper url, TypedEntity entity, string propertyAlias, int size) { //TODO: There is a lot of duplication between this and the MediaProxyController (with slight differences). Need to find a way to reuse code. var appContext = DependencyResolver.Current.GetService <IUmbracoApplicationContext>(); using (var securityUow = appContext.Hive.OpenReader <ISecurityStore>()) { // Get anonymous role var resultIds = entity.Id.AsEnumerableOfOne().ToArray(); using (var contentUow = appContext.Hive.OpenReader <IContentStore>()) resultIds = resultIds.FilterAnonymousWithPermissions(appContext.Security, contentUow, securityUow, new Guid(FixedPermissionIds.View)).ToArray(); // Check to see if anonymous view is allowed var anonymousViewAllowed = resultIds.Length != 0; // Get upload property var prop = propertyAlias.IsNullOrWhiteSpace() ? entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.AttributeType.RenderTypeProvider.InvariantEquals(CorePluginConstants.FileUploadPropertyEditorId)) : entity.Attributes.SingleOrDefault(x => x.AttributeDefinition.Alias == propertyAlias); if (prop == null || !prop.Values.ContainsKey("MediaId")) { return(null); // Couldn't find property so return null } var mediaId = prop.Values["MediaId"].ToString(); var fileId = new HiveId(prop.Values["Value"].ToString()); // Get the file using (var fileUow = appContext.Hive.OpenReader <IFileStore>(fileId.ToUri())) { var file = fileUow.Repositories.Get <File>(fileId); if (file == null) { return(null); // Couldn't find file so return null } // Fetch the thumbnail if (size > 0) { var relation = fileUow.Repositories.GetLazyChildRelations(fileId, FixedRelationTypes.ThumbnailRelationType) .SingleOrDefault(x => x.MetaData.Single(y => y.Key == "size").Value == size.ToString()); file = (relation != null && relation.Destination != null) ? (File)relation.Destination : null; } if (file == null) { return(null); // Couldn't find file so return null } if (anonymousViewAllowed && !file.PublicUrl.StartsWith("~/App_Data/")) // Don't proxy { return(url.Content(file.PublicUrl)); } else // Proxy { //NOTE: THIS IS TEMPORARY CODE UNTIL MEMBER PERMISSIONS IS DONE if (anonymousViewAllowed) { // If they are anonymous, but media happens to be in app_data folder proxy return(url.Action("Proxy", "MediaProxy", new { area = "", propertyAlias = prop.AttributeDefinition.Alias, mediaId, size, fileName = file.Name })); } return(null); // Check permissions //var authAttr = new UmbracoAuthorizeAttribute {AllowAnonymous = true, Permissions = new [] { FixedPermissionIds.View }}; //var authorized = authAttr.IsAuthorized(url.RequestContext.HttpContext, entity.Id); //if (!authorized) // return null; // Not authorized so return null //return url.Action("Proxy", "MediaProxy", new { area = "", propertyAlias = prop.AttributeDefinition.Alias, mediaId, size, fileName = file.Name }); } } } }
public static MvcHtmlString LinkEntity(this HtmlHelper html, string controler, string action, object id, object text) { //<a href="type/action/id">type.Name</a> var urlHelper = new UrlHelper(html.ViewContext.RequestContext); var builder = new TagBuilder("a"); builder.MergeAttribute("href", urlHelper.Action(action, controler, new { Id = id })); builder.SetInnerText(text.ToString()); string Html = builder.ToString(TagRenderMode.Normal); return MvcHtmlString.Create(Html); }
public static string Action(this UrlHelper helper) { var actionName = helper.RequestContext.RouteData.GetRequiredString("Action"); return(helper.Action(actionName)); }
public static string LogOff(this UrlHelper url) { return(url.Action(MVC.Authentication.LogOff(url.Current()))); }
private ApplicationPath GetIdeaApplicationPath(OrganizationServiceContext context, Entity idea) { idea.AssertEntityName("adx_idea"); var httpContext = HttpContext.Current; if (httpContext == null) { return(null); } var partialUrl = idea.GetAttributeValue <string>("adx_partialurl"); if (string.IsNullOrEmpty(partialUrl)) { return(null); } var ideaForumEntityReference = idea.GetAttributeValue <EntityReference>("adx_ideaforumid"); if (ideaForumEntityReference == null) { return(null); } var forum = context.CreateQuery("adx_ideaforum").FirstOrDefault(e => e.GetAttributeValue <EntityReference>("adx_ideaforumid").Id == ideaForumEntityReference.Id); if (forum == null) { return(null); } var forumPartialUrl = forum.GetAttributeValue <string>("adx_partialurl"); if (string.IsNullOrEmpty(forumPartialUrl)) { return(null); } var httpContextWrapper = new HttpContextWrapper(HttpContext.Current); var routeData = RouteTable.Routes.GetRouteData(httpContextWrapper); if (routeData == null) { return(null); } var urlHelper = new UrlHelper(new RequestContext(httpContextWrapper, routeData)); // If multi-language is enabled, return URL using in approriate multi-language URL format. var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo(); string url = string.Empty; if (contextLanguageInfo.IsCrmMultiLanguageEnabled && ContextLanguageInfo.DisplayLanguageCodeInUrl) { url = string.Format("{0}{1}", httpContext.Request.Url.GetLeftPart(UriPartial.Authority), urlHelper.Action("Ideas", "Ideas", new { ideaForumPartialUrl = forumPartialUrl, ideaPartialUrl = partialUrl, area = "Ideas" })); url = contextLanguageInfo.FormatUrlWithLanguage(false, contextLanguageInfo.ContextLanguage.Code, new Uri(url)); } else { url = urlHelper.Action("Ideas", "Ideas", new { ideaForumPartialUrl = forumPartialUrl, ideaPartialUrl = partialUrl, area = "Ideas" }); } return(url == null ? null : ApplicationPath.FromAbsolutePath(url)); }
public static string UploadPackage(this UrlHelper url) { return(url.Action(MVC.Packages.UploadPackage())); }
/// <summary> /// Create an Ajax.ActionLink with an associated glyphicon /// </summary> /// <param name="ajaxHelper"></param> /// <param name="linkText"></param> /// <param name="actionName"></param> /// <param name="controllerName"></param> /// <param name="glyphicon"></param> /// <param name="ajaxOptions"></param> /// <param name="routeValues"></param> /// <param name="htmlAttributes"></param> /// <returns></returns> public static MvcHtmlString GlyphiconActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, string glyphicon, AjaxOptions ajaxOptions, RouteValueDictionary routeValues = null, object htmlAttributes = null) { //Exemple of result: //<a id="btnShow" href="/Customers/ShowArtworks?customerId=1" data-ajax-update="#pnlArtworks" data-ajax-success="jsSuccess" //data-ajax-mode="replace" data-ajax-method="POST" data-ajax-failure="jsFailure" data-ajax-confirm="confirm" data-ajax-complete="jsComplete" //data-ajax-begin="jsBegin" data-ajax="true"> // <i class="glyphicon glyphicon-pencil"></i> // <span>Edit</span> //</a> var builderI = new TagBuilder("i"); builderI.MergeAttribute("class", "glyphicon " + glyphicon); string iTag = builderI.ToString(TagRenderMode.Normal); string spanTag = ""; if (!string.IsNullOrWhiteSpace(linkText)) { var builderSPAN = new TagBuilder("span"); builderSPAN.InnerHtml = " " + linkText; spanTag = builderSPAN.ToString(TagRenderMode.Normal); } //Create the "a" tag that wraps var builderA = new TagBuilder("a"); var uh = new UrlHelper(HttpContext.Current.Request.RequestContext); builderA.MergeAttribute("href", uh.Action(actionName, controllerName, routeValues.FixIEnumerables())); //Ajax section builderA.MergeAttribute("data-ajax", "true"); builderA.MergeAttribute("data-ajax-update", ajaxOptions.UpdateTargetId.StartsWith("#") ? ajaxOptions.UpdateTargetId : "#" + ajaxOptions.UpdateTargetId); if (!string.IsNullOrEmpty(ajaxOptions.InsertionMode.ToString())) { builderA.MergeAttribute("data-ajax-mode", ajaxOptions.InsertionMode.ToString()); } if (!string.IsNullOrEmpty(ajaxOptions.OnBegin)) { builderA.MergeAttribute("data-ajax-begin", ajaxOptions.OnBegin); } if (!string.IsNullOrEmpty(ajaxOptions.OnComplete)) { builderA.MergeAttribute("data-ajax-complete", ajaxOptions.OnComplete); } if (!string.IsNullOrEmpty(ajaxOptions.OnFailure)) { builderA.MergeAttribute("data-ajax-failure", ajaxOptions.OnFailure); } if (!string.IsNullOrEmpty(ajaxOptions.OnSuccess)) { builderA.MergeAttribute("data-ajax-success", ajaxOptions.OnSuccess); } if (!string.IsNullOrEmpty(ajaxOptions.Confirm)) { builderA.MergeAttribute("data-ajax-confirm", ajaxOptions.Confirm); } if (!string.IsNullOrEmpty(ajaxOptions.HttpMethod)) { builderA.MergeAttribute("data-ajax-method", ajaxOptions.HttpMethod); } if (htmlAttributes != null) { IDictionary <string, object> attributes = new RouteValueDictionary(htmlAttributes); builderA.MergeAttributes(attributes); } builderA.InnerHtml = iTag + spanTag; return(new MvcHtmlString(builderA.ToString(TagRenderMode.Normal))); }
public static string DeletePackage(this UrlHelper url, IPackageVersionModel package) { return(url.Action(MVC.Packages.Delete(package.Id, package.Version))); }
public static string PackageList(this UrlHelper url, int page, string sortOrder, string searchTerm) { return(url.Action(MVC.Packages.ListPackages(searchTerm, sortOrder, page))); }
/// <summary> /// 根据参数获得当前上下午参数集合 /// </summary> /// <param name="httpContext">httpcontext</param> /// <param name="routeData">路由集合</param> /// <param name="areaName">area</param> /// <param name="controllerName">控制器</param> /// <param name="actionName">action</param> /// <returns>返回生成的url</returns> public static string GetUrlByParameter(HttpContextBase httpContext, RouteData routeData, string areaName, string controllerName, string actionName) { var url = new UrlHelper(new RequestContext(httpContext, routeData)); return(url.Action(actionName, controllerName, new { area = areaName })); }