public static IHtmlContent MenuLink(this IHtmlHelper helper, string area, string controllerName, string actionName, string linkText, string classNames) { if (controllerName != "") { var routeData = helper.ViewContext.RouteData.Values; var currentController = routeData["controller"]; var currentAction = routeData["action"]; if (String.Equals(actionName, currentAction as string, StringComparison.OrdinalIgnoreCase) && String.Equals(controllerName, currentController as string, StringComparison.OrdinalIgnoreCase)) { classNames = classNames + " active"; var activeLink = helper.ActionLink(linkText, actionName, controllerName, new { area }, new { @class = classNames, title = linkText, itemprop = "url" } ); return(activeLink); } var link = helper.ActionLink(linkText, actionName, controllerName, new { area }, new { @class = classNames, title = linkText, itemprop = "url" } ); return(link); } else { return(new HtmlString(string.Format("<a href='{0}' itemprop='url' class='{1}'>{2}</a>", actionName, classNames, linkText))); } }
public static IHtmlContent BuildBreadcrumbNavigation(this IHtmlHelper helper) { if (helper.ViewContext.RouteData.Values["controller"].ToString() == "Home" || helper.ViewContext.RouteData.Values["controller"].ToString() == "Account") { return(_emptyBuilder); } string controllerName = helper.ViewContext.RouteData.Values["controller"].ToString(); string actionName = helper.ViewContext.RouteData.Values["action"].ToString(); var breadcrumb = new HtmlContentBuilder() .AppendHtml("<ol class='breadcrumb'><li>") .AppendHtml(helper.ActionLink("Home", "Index", "Home")) .AppendHtml("</li><li>") .AppendHtml(helper.ActionLink(controllerName.FirstLetterToUpperCase(), "Index", controllerName)) .AppendHtml("</li>"); if (helper.ViewContext.RouteData.Values["action"].ToString() != "Index") { breadcrumb.AppendHtml("<li>") .AppendHtml(helper.ActionLink(actionName.FirstLetterToUpperCase(), actionName, controllerName)) .AppendHtml("</li>"); } return(breadcrumb.AppendHtml("</ol>")); }
private static string buildActionLink(IHtmlHelper helper, string linkText, int pageParam) { if (helper.ViewContext.HttpContext.Request.QueryString.HasValue) { var queryString = QueryHelpers.ParseQuery(helper.ViewContext.HttpContext.Request.QueryString.Value); //string[] sort, categoryId; StringValues sort, categoryId; queryString.TryGetValue("SortExpression", out sort); queryString.TryGetValue("CategoryId", out categoryId); return(helper.ActionLink(linkText, helper.ViewContext.RouteData.Values["action"].ToString(), new { SortExpression = sort, Genres = categoryId, Page = pageParam }).ToString()); } else { return(helper.ActionLink(linkText, helper.ViewContext.RouteData.Values["action"].ToString(), new { Page = pageParam }).ToString()); } }
public static IHtmlContent ActionLink <TController>(this IHtmlHelper html, Expression <Action <TController> > expression, string linkText, object htmlAttributes = null, Boolean passRouteValues = true) where TController : ControllerBase { var result = Helpers.ExpressionHelper.GetRouteValuesFromExpression <TController>(expression); result.RouteValues.Remove("Action"); result.RouteValues.Remove("Controller"); IDictionary <string, object> htmlAttributesDict = null; if (htmlAttributes != null) { htmlAttributesDict = (IDictionary <string, object>) new RouteValueDictionary(htmlAttributes); } else { htmlAttributesDict = new Dictionary <string, object>(); } if (passRouteValues) { return(html.ActionLink(linkText, result.Action, result.Controller, result.RouteValues, htmlAttributesDict)); } else { return(html.ActionLink(linkText, result.Action, result.Controller, new RouteValueDictionary(), htmlAttributesDict)); } }
public static IHtmlContent AutoDisplayFor <T>(this IHtmlHelper <T> html, PropertyInfo property, object htmlAttributes = null) { if (property.HasAttribute(typeof(KeyAttribute)) || property.HasAttribute(typeof(IgnoreAttribute))) { return(null); } switch (property.GetRelation()) { case Relation.None: return(html.Display(property.Name)); case Relation.OneToOne: return(html.ActionLink(/*property.GetValue(html.ViewData.Model)?.ToString()*/ "View", "Details", new { table = property.PropertyType.Name, id = property.GetValue(html.ViewData.Model)?.GetPrimaryKeyValue() })); case Relation.OneToMany: return(html.ActionLink(/*property.GetValue(html.ViewData.Model)?.ToString()*/ "View All", "Index", new RouteValueDictionary(new Dictionary <string, object>() { { "table", (property.PropertyType.IsConstructedGenericType ? property.PropertyType.GetGenericArguments()[0] : property.PropertyType).GetTableName() }, { property.DeclaringType.GetTypePrimaryKeyName(), $"'{html.ViewData.Model.GetPrimaryKeyValue()}'" }, }))); case Relation.ManyToOne: case Relation.ManyToMany: return(html.Display(property.Name)); } return(html.Display(property.Name, null, null, null)); }
public static HtmlString MenuLink(this IHtmlHelper helper, string area, string controllerName, string actionName, string linkText, string classNames, string iconClass = "", string content = "") { var routeData = helper.ViewContext.RouteData.Values; var currentController = routeData["controller"]; var currentAction = routeData["action"]; var urlHelperFactory = helper.ViewContext.HttpContext.RequestServices.GetRequiredService <IUrlHelperFactory>(); var urlHelper = urlHelperFactory.GetUrlHelper(helper.ViewContext); var linkGenerator = helper.ViewContext.HttpContext.RequestServices.GetRequiredService <LinkGenerator>(); if (String.Equals(actionName, currentAction as string, StringComparison.OrdinalIgnoreCase) && String.Equals(controllerName, currentController as string, StringComparison.OrdinalIgnoreCase)) { classNames = classNames + " active"; HtmlString activeLink = null; if (!string.IsNullOrEmpty(iconClass)) { activeLink = new HtmlString(string.Format(@"<a href=""{0}"" class=""{1}"" title=""{2}""><i class=""fa {3}""></i></a>", urlHelper.Action(actionName, controllerName, new { area }), classNames, linkText, iconClass)); } else if (!string.IsNullOrEmpty(content)) { activeLink = new HtmlString(string.Format(@"<a href=""{0}"" class=""{1}"" title=""{2}"">{3}{2}</a>", urlHelper.Action(actionName, controllerName, new { area }), classNames, linkText, content)); } else { activeLink = new HtmlString(helper.ActionLink(linkText, actionName, controllerName, new { area }, new { @class = classNames, title = linkText } ).Render()); } return(activeLink); } HtmlString link = null; if (!string.IsNullOrEmpty(iconClass)) { link = new HtmlString(string.Format(@"<a href=""{0}"" class=""{1}"" title=""{2}""><i class=""fa {3}""></i></a>", urlHelper.Action(actionName, controllerName, new { area }), classNames, linkText, iconClass)); } else if (!string.IsNullOrEmpty(content)) { link = new HtmlString(string.Format(@"<a href=""{0}"" class=""{1}"" title=""{2}"">{3}{2}</a>", urlHelper.Action(actionName, controllerName, new { area }), classNames, linkText, content)); } else { link = new HtmlString(helper.ActionLink(linkText, actionName, controllerName, new { area }, new { @class = classNames, title = linkText } ).Render()); } return(link); }
private static IHtmlContent PEPager(this IHtmlHelper htmlHelper, int start, int count, int total, RouteValueDictionary routeValues, object htmlAttributes, string action) { HtmlContentBuilder retvalue = new HtmlContentBuilder(); if (start > 1) { RouteValueDictionary linkRd = CopyRVD(routeValues); linkRd.Add("start", 1); linkRd.Add("count", count); retvalue.AppendHtml(htmlHelper.ActionLink("[Start]", action, linkRd, new RouteValueDictionary(htmlAttributes))); retvalue.AppendHtml(" "); linkRd = CopyRVD(routeValues); linkRd.Add("start", start - count); linkRd.Add("count", count); retvalue.AppendHtml(htmlHelper.ActionLink("[Prev]", action, linkRd, new RouteValueDictionary(htmlAttributes))); } else { if (total > count) { retvalue.AppendHtml("[Start] [Prev]"); } } if (total > count) { retvalue.AppendHtml(string.Format(" <span>{0} to {1} of {2}</span> ", start, total < start + count ? total : start + count - 1, total)); } else { retvalue.AppendHtml(string.Format(" <span>{0} of {0} ", total)); } if (total > (start + count) - 1) { RouteValueDictionary linkRd = CopyRVD(routeValues); linkRd.Add("start", start + count); linkRd.Add("count", count); retvalue.AppendHtml(htmlHelper.ActionLink("[Next]", action, linkRd, new RouteValueDictionary(htmlAttributes))); retvalue.AppendHtml(" "); linkRd = CopyRVD(routeValues); linkRd.Add("start", (total - (total % count)) + 1); linkRd.Add("count", count); retvalue.AppendHtml(htmlHelper.ActionLink("[End]", action, linkRd, new RouteValueDictionary(htmlAttributes))); } else { if (total > count) { retvalue.AppendHtml("[Next] [End]"); } } return(retvalue); }
public static IHtmlContent MenuLink(this IHtmlHelper htmlHelper, string linkText, string actionName, string controllerName ) { //var currentAction = htmlHelper.ViewContext.RouteData.Values["action"].ToString(); var currentController = htmlHelper.ViewContext.RouteData.Values["controller"].ToString(); return(controllerName == currentController ? htmlHelper.ActionLink(linkText, actionName, controllerName, null, null, null, null, new { @class = "nav-link active" }) : htmlHelper.ActionLink(linkText, actionName, controllerName, null, null, null, null, new { @class = "nav-link" })); }
public static IHtmlContent SortableHeaderFor <TModelItem, TResult>(this IHtmlHelper <IEnumerable <TModelItem> > hh, Expression <Func <TModelItem, TResult> > columnExpression, string currentSortColName = null, string currentSortDir = null, string actionName = null, string overrideDisplayName = null) { currentSortColName = currentSortColName ?? hh.ViewBag.SortCol as string; currentSortDir = currentSortDir ?? hh.ViewBag.SortDir as string; actionName = actionName ?? hh.ViewContext.RouteData.Values["action"] as string; var colName = columnExpression.GetFullyQualifiedName(); var displayName = overrideDisplayName ?? hh.FriendlyNameFor(columnExpression); var routeValues = new RouteValueDictionary(); foreach (string key in hh.ViewContext.HttpContext.Request.Query.Keys) { if (key == null) { continue; } var val = hh.ViewContext.HttpContext.Request.Query[key]; if (val.Count != 0) { routeValues[key] = val; } } routeValues["sortCol"] = colName; if (colName == currentSortColName) { routeValues["sortDir"] = IsSortDirAscending(currentSortDir) ? SortDirDescending : SortDirAscending; var h = hh.ActionLink( displayName, actionName, routeValues); var htmlList = new List <object> { h }; var builder = new HtmlContentBuilder(htmlList); if (currentSortDir != null) { var html = builder.AppendHtml(currentSortDir == SortDirAscending ? " <span class='caret-up'>▲</span>" : " <span class='caret-down'>▼</span>"); return(html); } return(builder); } else { routeValues["sortDir"] = SortDirAscending; return(hh.ActionLink(displayName, actionName, routeValues)); } }
/// <summary> /// Generates a editor for current property /// </summary> public static IHtmlContent AutoEditorFor <T>(this IHtmlHelper <T> html, PropertyInfo property, object htmlAttributes = null) { if (property.HasAttribute(typeof(KeyAttribute)) || property.HasAttribute(typeof(IgnoreAttribute))) { return(null); } //if (property.HasAttribute(typeof(IgnoreAttribute))) // return html.Hidden(property.Name); var _relation = property.GetRelation(); switch (_relation) { case Relation.OneToOne: return(html.Editor(property.Name, new { htmlAttributes = htmlAttributes ?? new { @class = "form-control" } })); case Relation.OneToMany: //dropdown return(html.ActionLink("OneToMany Action", "Edit", "Admin", new { table = property.PropertyType.Name }, new { @class = "btn btn-primary" })); case Relation.ManyToOne: return(html.DropDownList( property.Name, html.ViewData[property.Name] .ToSelectList(property.GetValue(html.ViewData.Model)?.GetPrimaryKeyValue()), new { @class = "selectpicker form-control" } )); case Relation.ManyToMany: return(html.DropDownList(html.ViewData.Model.GetPropertyFromType(property.PropertyType)?.Name, html.ViewData[property.Name].ToSelectList(), new { @class = "selectpicker form-control", multiple = "multiple" })); case Relation.None: if (property.PropertyType == typeof(bool)) { //return IHtmlContent.Create(""); return(new HtmlContentBuilder().AppendHtml("")); } return(html.Editor(property.Name, new { htmlAttributes = htmlAttributes ?? new { @class = "form-control" } })); default: break; } return(html.ActionLink("Could not found editor for", "Index", "Admin", new { table = property.DeclaringType.Name })); }
/// <summary> /// Allows or blocks the display of an action link depending on user authorization level. /// </summary> public static IHtmlContent ActionLinkAuth(this IHtmlHelper htmlHelper, Enumerations.Role requiredPrivilege, Enumerations.AuthFailedBehaviour authFailedBehaviour, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes, string alternateLinkText) { //If no link text, just return an empty string. if (string.IsNullOrEmpty(linkText)) { return(HtmlString.Empty); } // If user has no privileges refuse access bool hasAccess = new UserSessionContext(htmlHelper.GetHttpContext()).UserHasAccess(requiredPrivilege); var htmlOptions = new RouteValueDictionary(htmlAttributes); var routeOptions = new RouteValueDictionary(routeValues); //Remove disabled attribute if present if (htmlOptions.ContainsKey("disabled")) { htmlOptions.Remove("disabled"); } IHtmlContent result = htmlHelper.ActionLink(linkText, actionName, controllerName, routeOptions, htmlOptions); if (!hasAccess) { switch (authFailedBehaviour) { case Enumerations.AuthFailedBehaviour.AlternateLink: if (string.IsNullOrEmpty(alternateLinkText)) { throw new ArgumentNullException("alternateLinkText", "alternateLinkText cannot be null or empty"); } result = htmlHelper.ActionLink(alternateLinkText, actionName, controllerName, routeOptions, htmlOptions); break; case Enumerations.AuthFailedBehaviour.EmptyString: result = HtmlString.Empty; break; case Enumerations.AuthFailedBehaviour.InnerHtml: result = htmlHelper.Span(linkText, htmlOptions); break; default: throw new ArgumentOutOfRangeException("authFailedBehaviour"); } } return(result); }
public static IHtmlContent BuildBreadcrumbNavigation(this IHtmlHelper helper) { if (helper.ViewContext.RouteData.Values["controller"].ToString() == "Home") { return(_emptyBuilder); } string controllerName = helper.ViewContext.RouteData.Values["controller"].ToString(); string actionName = helper.ViewContext.RouteData.Values["action"].ToString(); var controllerAlias = ""; if (controllerName == "OperationTypes") { controllerAlias = controllerName.Replace("OperationTypes", "Operation Types"); } else if (controllerName == "LoginLog") { controllerAlias = "Login Times"; } else { controllerAlias = controllerName; } if (!controllerName.Titleize().EndsWith("s")) { controllerAlias = controllerName + "s"; } var breadcrumb = new HtmlContentBuilder() .AppendHtml("<ol class='breadcrumb'><li class='breadcrumb-item'>") .AppendHtml(helper.ActionLink("Home", "Index", "Home")) .AppendHtml("</li><li class='breadcrumb-item'>") .AppendHtml(helper.ActionLink(controllerAlias.Titleize(), "Index", controllerName)) .AppendHtml("</li>"); if (helper.ViewContext.RouteData.Values["action"].ToString() != "Index" && controllerName != "Reports") { breadcrumb.AppendHtml("<li class='breadcrumb-item'>") .AppendHtml(helper.ActionLink(actionName.Titleize().Replace("Operationsreport", "Operations Report"), actionName, controllerName)) .AppendHtml("</li>"); } return(breadcrumb.AppendHtml("</ol>")); }
/// <summary> /// SparkActionLink /// </summary> /// <param name="helper">HtmlHelper</param> /// <param name="linkText">linkText</param> /// <param name="actionName">actionName</param> /// <param name="controllerName">controllerName</param> /// <param name="routeValues">routeValues</param> /// <param name="htmlAttributes">htmlAttributes</param> /// <param name="accessKey">accessKey</param> /// <returns></returns> public static IHtmlContent SparkActionLink(this IHtmlHelper helper, string linkText, string actionName, string controllerName = "", object routeValues = null, object htmlAttributes = null, string accessKey = "") { if (_accessStrategy.IsControlCanAccess(accessKey)) { if (String.IsNullOrEmpty(controllerName)) { return(helper.ActionLink(linkText, actionName, routeValues, htmlAttributes)); } else { return(helper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes)); } } return(HtmlString.Empty); }
private static IHtmlContent AjaxRenderSearchPageAndPageSizeDiv <T>(IHtmlHelper helper, TargetPager <T> dataList, string divClassName, object routeValues, string updateTarget, string action, string controller) { HtmlContentBuilder pagerHtmlContentBuilder = new HtmlContentBuilder(); string goelementId = updateTarget + "_pageIndexInputId"; string perPageelementId = updateTarget + "_pager_pagesize_selectid"; IHtmlContent ajaxLink = helper.ActionLink("Go", action, controller, routeValues, new { data_ajax = "true", data_ajax_method = "Post", data_ajax_mode = "replace", data_ajax_update = "#" + updateTarget, @class = "go", @onclick = "setJumpPagerLinkWithGo(" + dataList.PageIndex + "," + dataList.PageTotal + "," + goelementId + "," + perPageelementId + ", this)" }); IHtmlContent ajaxLinkHide = helper.ActionLink("Go", action, controller, routeValues, new { data_ajax = "true", data_ajax_method = "Post", data_ajax_mode = "replace", data_ajax_update = "#" + updateTarget, @id = updateTarget + "_perPageHiddenGo", @hidden = "hidden", @onclick = "setJumpPagerLinkWithPerPage(" + dataList.PageIndex + "," + dataList.PageTotal + "," + perPageelementId + ", this )" }); pagerHtmlContentBuilder.AppendHtml(AjaxRenderToPageDiv(dataList, ajaxLink, updateTarget)); pagerHtmlContentBuilder.AppendHtml(AjaxRenderSetSizeDiv(dataList, ajaxLinkHide, updateTarget)); return(pagerHtmlContentBuilder); }
public static IHtmlContent PagerButton(this IHtmlHelper htmlHelper, string text, string action, object routeValues, params string[] additionalClasses) { /* * <li class="paginate_button previous disabled" tabindex="0"> * <a href="#">Previous</a> * </li> */ TagBuilder li = new TagBuilder(Constants.DOM.LI); li.AddCssClass(Constants.Css.PAGINATION_BUTTON); if (additionalClasses != null) { foreach (var item in additionalClasses) { li.AddCssClass(item); } } if (routeValues == null) { TagBuilder a = new TagBuilder(Constants.DOM.A); a.Attributes[Constants.HtmlAttribute.HREF] = Constants.HASH_LINK; a.InnerHtml.SetContent(text); li.InnerHtml.SetContent(a.ToString()); } else { li.InnerHtml.SetContent(htmlHelper.ActionLink(text, action, routeValues).ToString()); } return(li); }
public static IHtmlContent SslActionLink( this IHtmlHelper helper, string linkText, string actionName, string controllerName) { if (helper == null) { throw new ArgumentNullException("helper"); } if (string.IsNullOrEmpty(linkText)) { throw new ArgumentNullException("linkText"); } return(helper.ActionLink( linkText, actionName, controllerName, protocol: "https", hostname: null, fragment: null, routeValues: null, htmlAttributes: null)); }
public static IHtmlContent BootstrapButtonActionLink <TModel>( this IHtmlHelper <TModel> helper, string linkText, string actionName, string controllerName, object routeValues = null, bool isEnabled = true, string classes = "btn btn-primary", IDictionary <string, object> htmlAttributes = null) { if (htmlAttributes == null) { htmlAttributes = new Dictionary <string, object>(); } if (!htmlAttributes.ContainsKey("class")) { if (isEnabled) { htmlAttributes["class"] = classes; } else { htmlAttributes["class"] = classes + " disabled"; } } return(helper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes));; }
/// <summary> /// SparkActionLink /// </summary> /// <param name="helper">HtmlHelper</param> /// <param name="linkText">linkText</param> /// <param name="actionName">actionName</param> /// <param name="controllerName">controllerName</param> /// <param name="routeValues">routeValues</param> /// <param name="htmlAttributes">htmlAttributes</param> /// <param name="accessKey">accessKey</param> /// <returns></returns> public static IHtmlContent SparkActionLink(this IHtmlHelper helper, string linkText, string actionName, string controllerName = "", object routeValues = null, object htmlAttributes = null, string accessKey = "") { if (helper.ViewContext.HttpContext.RequestServices.GetRequiredService <IControlAccessStrategy>() .IsControlCanAccess(accessKey)) { if (string.IsNullOrEmpty(controllerName)) { return(helper.ActionLink(linkText, actionName, routeValues, htmlAttributes)); } else { return(helper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes)); } } return(HtmlString.Empty); }
private static IHtmlContent DisplayNavigationProperty(IHtmlHelper helper, object record, PropertySchema propertySchema) { INavigation property = propertySchema.Property as INavigation; var relation = property.IsCollection() ? new // one-to-many relation { ForeignEntityType = property.ForeignKey.DeclaringEntityType, ForeignEntityProperties = property.ForeignKey.Properties, PrincipalProperties = property.ForeignKey.PrincipalKey.Properties, } : new // many-to-one or one-to-one relation { ForeignEntityType = property.ForeignKey.PrincipalEntityType, ForeignEntityProperties = property.ForeignKey.PrincipalKey.Properties, PrincipalProperties = property.ForeignKey.Properties, }; var queryParameters = relation.ForeignEntityProperties .Zip(relation.PrincipalProperties, (foreign, principal) => new { Parameter = foreign.Name, Value = principal.GetGetter().GetClrValue(record) }) .ToDictionary(kvp => kvp.Parameter, kvp => kvp.Value); queryParameters["table"] = relation.ForeignEntityType.Name; return(helper.ActionLink("View", "ListRecords", "Home", queryParameters, null)); }
public static HtmlString IconLink(this IHtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, String iconName, object htmlAttributes = null) { var linkMarkup = htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes).Render().Replace("%2F", "/"); var iconMarkup = String.Format("<span class=\"{0}\" aria-hidden=\"true\"></span> ", iconName); return(new HtmlString(linkMarkup.Insert(linkMarkup.IndexOf(@">") + 1, iconMarkup))); }
public static IHtmlContent PrettyJoin(this IHtmlHelper html, IEnumerable <Person> persons) { Func <Person, IHtmlContent> linkify = person => html.ActionLink(person.Name, "Details", "Person", new { id = person.PersonId }, null); var writer = new StringWriter(); var enc = HtmlEncoder.Default; int personsCount = persons.Count(); int counter = 0; foreach (var person in persons) { counter++; if (counter == personsCount) { writer.Write(" og "); } else if (counter > 1) { writer.Write(", "); } linkify(person).WriteTo(writer, enc); } return(new HtmlString(writer.ToString())); }
public override IHtmlContent Render(IHtmlHelper html) { FillMissingAttributes(); var expandableItem = new TagBuilder("li"); if (InnerContent?.Any() ?? false) { expandableItem.AddCssClass("expandable"); } expandableItem.AddCssClass("slider-menu-item"); expandableItem.Attributes["id"] = $"{Caption.ToLower().Replace(" ", "_")}-submodels"; var link = html.ActionLink(Caption.ToUpper(), Action, Controller, new { brandID = RouteValues }); var subGroup = new TagBuilder("div"); subGroup.AddCssClass("sub-group"); subGroup.InnerHtml.AppendHtml(RenderSubmenuHeader(html)); foreach (var model in InnerContent) { subGroup.InnerHtml.AppendHtml(model.Render(html)); } expandableItem.InnerHtml.AppendHtml(link); expandableItem.InnerHtml.AppendHtml(subGroup); return(expandableItem); }
public static IHtmlContent PagedList(this IHtmlHelper htmlHelper) { var pagedResult = htmlHelper.ViewData.Model as PagedResultBase; TagBuilder ulTag = new TagBuilder("ul"); ulTag.AddCssClass("pagination"); for (int i = 0; i < pagedResult.PageCount; i++) { var aTag = htmlHelper.ActionLink((i + 1).ToString(), "Index", new { page = i + 1 }, new { @class = "page-link" }); TagBuilder liTag = new TagBuilder("li"); liTag.AddCssClass("page-item"); if (pagedResult.CurrentPage == (i + 1)) { liTag.AddCssClass("active"); } liTag.InnerHtml.AppendHtml(aTag); ulTag.InnerHtml.AppendHtml(liTag); } return(ulTag); }
public static HtmlString ActionGroup(this IHtmlHelper helper, int route, string defaultAction = "Detail", string descriptionAction = "Detalhes", bool editable = true, bool removible = true, params Tuple <string, string>[] customActions) { string actions = string.Empty; if (editable) { actions += CreateActionLink(helper, action: "Edit", route: route, description: "Editar"); } if (removible) { actions += CreateActionLink(helper, action: "Delete", route: route, description: "Remover"); } if (customActions.Length > 0) { actions += "<li role=\"separator\" class=\"divider\"></li>"; foreach (var action in customActions) { actions += CreateActionLink(helper, action.Item1, route, action.Item2); } } string html = $@"<div class='btn-group'> {helper.ActionLink(descriptionAction, defaultAction, new { id = route }, new { @class = "btn btn-default btn-sm" }).ToHtmlString()} <button type='button' class='btn btn-default btn-sm dropdown-toggle' data-toggle='dropdown'> <span class='caret'></span> </button> <ul class='dropdown-menu'>{actions}</ul> </div>"; return(new HtmlString(string.Concat("<td> ", html, "</td> "))); }
/// <summary> /// Returns an anchor (<a>) element that contains a URL path to the specified action. /// </summary> /// <param name="helper">The <see cref="IHtmlHelper"/> instance this method extends.</param> /// <param name="linkText">The inner text of the anchor element. Must not be <c>null</c>.</param> /// <param name="actionName">The name of the action.</param> /// <param name="routeValues"> /// An <see cref="object"/> that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the <see cref="object"/>. This <see cref="object"/> is typically /// created using <see cref="object"/> initializer syntax. Alternatively, an /// <see cref="System.Collections.Generic.IDictionary{string, object}"/> instance containing the route /// parameters. /// </param> /// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns> public static IHtmlContent ActionLink( this IHtmlHelper helper, string linkText, string actionName, object routeValues) { if (helper == null) { throw new ArgumentNullException(nameof(helper)); } if (linkText == null) { throw new ArgumentNullException(nameof(linkText)); } return(helper.ActionLink( linkText, actionName, controllerName: null, protocol: null, hostname: null, fragment: null, routeValues: routeValues, htmlAttributes: null)); }
public static IHtmlContent MenuItem( this IHtmlHelper htmlHelper, string text, string action, string controller, string icon, object routeValues = null, object htmlAttributes = null ) { var a = htmlHelper.ActionLink("", action, controller, routeValues, htmlAttributes) as TagBuilder; var routeData = htmlHelper.ViewContext.RouteData; var currentAction = routeData.Values["action"].ToString(); var currentController = routeData.Values["controller"].ToString(); a.AddCssClass("nav-link"); var i = new TagBuilder("i"); i.AddCssClass("sidebar-nav-item-icon " + icon); a.InnerHtml.AppendHtml(i); a.InnerHtml.Append(text); var li = new TagBuilder("li"); li.InnerHtml.AppendHtml(a); if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) && string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase)) { li.AddCssClass("active"); } return(li); }
public static IHtmlContent SortableHeaderFor <TModel, TValue>( this IHtmlHelper <PagingList <TModel> > html, Expression <Func <TModel, TValue> > expression, string sortColumn) where TModel : class { var htmlContent = new HtmlContentBuilder(); htmlContent.AppendHtml( html.ActionLink( html.DisplayNameForInnerType(expression), html.ViewData.Model.Action, html.ViewData.Model.GetRouteValueForSort(sortColumn)) ); IPagingList pagingList = html.ViewData.Model; if (pagingList.SortExpression == sortColumn || "-" + pagingList.SortExpression == sortColumn || pagingList.SortExpression == "-" + sortColumn) { htmlContent.AppendHtml( pagingList.SortExpression.StartsWith("-") ? PagingOptions.Current.HtmlIndicatorUp : PagingOptions.Current.HtmlIndicatorDown); } return(htmlContent); }
public static IHtmlContent DisplayForUser(this IHtmlHelper helper, UserDisplayModel model, Guid?userId) { string name = HttpUtility.HtmlEncode(model.Name); string username = HttpUtility.HtmlEncode(model.UserName.ToLower()); string linkText = userId == model.Id ? "you" : $"{name} <{username}>"; return(helper.ActionLink(linkText, "GetUser", "Users", new { userName = username }, new { })); }
public static IHtmlContent BuildBreadcrumbNavigation(this IHtmlHelper helper) { string controllerName = helper.ViewContext.RouteData.Values["controller"].ToString(); string actionName = helper.ViewContext.RouteData.Values["action"].ToString(); var breadcrumb = new HtmlContentBuilder() .AppendHtml(helper.ActionLink("Home", "Index", "Home", null, new { @class = "breadcrumb" })) .AppendHtml(helper.ActionLink(Titleize(controllerName), "Index", controllerName, null, new { @class = "breadcrumb" })); if (helper.ViewContext.RouteData.Values["action"].ToString() != "Index") { breadcrumb.AppendHtml(helper.ActionLink(Titleize(actionName), actionName, controllerName, null, new { @class = "breadcrumb" })); } return(breadcrumb.AppendHtml("")); }
public static TagBuilder FALink(this IHtmlHelper html, string controller, string action, string iconClass, object routeValues = null, object htmlAttributes = null) { TagBuilder a = (TagBuilder)html.ActionLink(string.Empty, action, controller, routeValues, htmlAttributes); TagBuilder i = new TagBuilder(Constants.DOM.I); i.AddCssClass(Constants.Css.FONT_AWESOME); i.AddClass(iconClass); a.InnerHtml.Append(i.ToString()); return(a); }
private static string buildActionLink(IHtmlHelper helper, string linkText, int pageParam) { if (helper.ViewContext.HttpContext.Request.QueryString.HasValue) { var queryString = QueryHelpers.ParseQuery(helper.ViewContext.HttpContext.Request.QueryString.Value); string[] sort, categoryId; queryString.TryGetValue("SortExpression", out sort); queryString.TryGetValue("CategoryId", out categoryId); return helper.ActionLink(linkText, helper.ViewContext.RouteData.Values["action"].ToString(), new { SortExpression = sort, CategoryId = categoryId, Page = pageParam }).ToString(); } else { return helper.ActionLink(linkText, helper.ViewContext.RouteData.Values["action"].ToString(), new { Page = pageParam }).ToString(); } }