public static string ProductActions(this HtmlHelper html, ProductoDTO producto, bool isDGAA) { var actions = String.Empty; if ((isDGAA && producto.IsFirmed()) || (!isDGAA && producto.IsValidated())) actions += String.Format("<span>{0}</span>", html.ActionLink("Editar", "Edit", "Home", new { id= producto.Id, tipoProducto = producto.TipoProducto }, null)); else if (!isDGAA) { if (!producto.IsFirmed() && !producto.IsValidated() && producto.UsuarioId == producto.CurrentUserId) { actions += String.Format("<span>{0}</span>", html.ActionLink("Editar", "Edit", "Home", new { id= producto.Id, tipoProducto = producto.TipoProducto }, null)); actions += String.Format("<span>{0}</span>", html.ActionLink("Firmar", "Sign", "Home", new { id= producto.Id, tipoProducto = producto.TipoProducto }, new { @class = "remote put"})); } else if (producto.IsFirmed() && !producto.IsValidated() || producto.UsuarioId != producto.CurrentUserId) { actions += String.Format("<span>{0}</span>", html.ActionLink("Ver", "Show", "Home", new { id= producto.Id, tipoProducto = producto.TipoProducto }, null)); } } return actions; }
public static IHtmlString DisplayNameForSort(this AjaxHelper helper, string displayName, string columName, string actionName, RouteValueDictionary routeValues, AjaxOptions ajaxOptions, string controllerName = null) { if (!string.IsNullOrWhiteSpace(columName)) { string orderBy; string iconName; HtmlHelperExtensions.GetListOrderParams(columName, out orderBy, out iconName); if (routeValues.ContainsKey("orderBy")) { routeValues["orderBy"] = orderBy; } else { routeValues.Add("orderBy", orderBy); } MvcHtmlString link; if (string.IsNullOrEmpty(controllerName)) { link = helper.ActionLink(displayName, actionName, routeValues, ajaxOptions); } else { link = helper.ActionLink(displayName, actionName, controllerName, routeValues, ajaxOptions); } string htmlStr = "<div class=\"ap-sortedHeader\">{0}<i class=\"ap-sortedHeader fa {1}\"></i></div>"; return new MvcHtmlString(string.Format(htmlStr, link.ToString(), iconName)); } else { return new MvcHtmlString(displayName); } }
public static MvcHtmlString MenuLink( this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string tooltip = "") { string currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action"); string currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller"); if (controllerName == "Home" && actionName=="Index") { return MenuLinkForMessages(htmlHelper, linkText, actionName, controllerName, tooltip); } if (actionName == currentAction && controllerName == currentController) { string classForElement = "currentMenuItem"; return htmlHelper.ActionLink( linkText, actionName, controllerName, null, new { @class = classForElement }); } return htmlHelper.ActionLink(linkText, actionName, controllerName); }
public static string BlogPager(this HtmlHelper helper, IPagedList pager) { // Don't display anything if not multiple pages if (pager.TotalPageCount == 1) return string.Empty; // Build route data var routeData = new RouteValueDictionary(helper.ViewContext.RouteData.Values); // Build string var sb = new StringBuilder(); // Render Newer Entries if (pager.PageIndex > 0) { routeData["page"] = pager.PageIndex - 1; sb.Append(helper.ActionLink("Newer Entries", "Index", routeData)); } // Render divider if (pager.PageIndex > 0 && pager.PageIndex < pager.TotalPageCount - 1) sb.Append(" | "); // Render Older Entries if (pager.PageIndex < pager.TotalPageCount - 1) { routeData["page"] = pager.PageIndex + 1; sb.Append(helper.ActionLink("Older Entries", "Index", routeData)); } return sb.ToString(); }
public static MvcHtmlString MenuItem(this HtmlHelper htmlHelper, string text, string action, string controller, int? categoryId = null, string cssClasses = null) { var li = new TagBuilder("li"); var routeData = htmlHelper.ViewContext.RouteData; var currentAction = routeData.GetRequiredString("action"); var currentController = routeData.GetRequiredString("controller"); if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) && string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase)) { li.AddCssClass("active"); } if (!string.IsNullOrEmpty(cssClasses)) { li.AddCssClass(cssClasses); } if (categoryId != null) { li.InnerHtml = htmlHelper.ActionLink(text, action, controller,new { id = categoryId.Value },new {}).ToHtmlString(); } else { li.InnerHtml = htmlHelper.ActionLink(text, action, controller).ToHtmlString(); } return MvcHtmlString.Create(li.ToString()); }
public static MvcHtmlString PrettyJoin(this HtmlHelper html, IEnumerable<Person> persons) { int count = 0; string res = ""; foreach (var person in persons) { switch (++count) { case 1: res = html.ActionLink(person.Name, "Details", "Person", new { id = person.PersonId }, null).ToString(); break; case 2: res = html.ActionLink(person.Name, "Details", "Person", new { id = person.PersonId }, null).ToString() + " og " + res; break; default: res = html.ActionLink(person.Name, "Details", "Person", new { id = person.PersonId }, null).ToString() + ", " + res; break; } } return MvcHtmlString.Create(res); }
public static MvcHtmlString MenuItem(this HtmlHelper htmlHelper, string text, string action, string controller, object routeValues = null, object htmlAttributes = null) { var li = new TagBuilder("li"); var routeData = htmlHelper.ViewContext.RouteData; var currentAction = routeData.GetRequiredString("action"); var currentController = routeData.GetRequiredString("controller"); if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) || string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase)) { li.AddCssClass("active"); } if (routeValues != null) { li.InnerHtml = (htmlAttributes != null) ? htmlHelper.ActionLink(text, action, controller, routeValues, htmlAttributes).ToHtmlString() : htmlHelper.ActionLink(text, action, controller, routeValues).ToHtmlString(); } else { li.InnerHtml = htmlHelper.ActionLink(text, action, controller).ToHtmlString(); } return MvcHtmlString.Create(li.ToString()); }
public static MvcHtmlString SiteMenu(this HtmlHelper helper, Tenant currentTenant) { ILinkService linkService = DependencyResolver.Current.GetService<ILinkService>(); if (currentTenant == null || linkService == null) { return null; } TagBuilder itemTag; IList<Link> menuItems = linkService.GetMenuLinks(currentTenant.Id.ToString()); TagBuilder menu = new TagBuilder("ul"); menu.MergeAttribute("id", "menu"); foreach (Link item in menuItems) { itemTag = new TagBuilder("li"); if (String.IsNullOrWhiteSpace(item.Area)) { itemTag.InnerHtml = helper.ActionLink(item.Name, item.Action, new { area = "", controller = item.Controller }).ToString(); } else { itemTag.InnerHtml = helper.ActionLink(item.Name, item.Action, new { area = item.Area, controller = item.Controller }).ToString(); } menu.InnerHtml += itemTag; } return MvcHtmlString.Create(menu.ToString()); }
public static string BuildBreadcrumbNavigation(this HtmlHelper helper) { // optional condition: I didn't wanted it to show on home and account controller if (helper.ViewContext.RouteData.Values["controller"].ToString() == "Home" || helper.ViewContext.RouteData.Values["controller"].ToString() == "Account") { return string.Empty; } StringBuilder breadcrumb = new StringBuilder("<div class=\"breadcrumb\"><li>").Append(helper.ActionLink("Home", "Index", "Home").ToHtmlString()).Append("</li>"); breadcrumb.Append("<li>"); breadcrumb.Append(helper.ActionLink(helper.ViewContext.RouteData.Values["controller"].ToString(), "Index", helper.ViewContext.RouteData.Values["controller"].ToString())); breadcrumb.Append("</li>"); if (helper.ViewContext.RouteData.Values["action"].ToString() != "Index") { breadcrumb.Append("<li>"); breadcrumb.Append(helper.ActionLink(helper.ViewContext.RouteData.Values["action"].ToString(), helper.ViewContext.RouteData.Values["action"].ToString(), helper.ViewContext.RouteData.Values["controller"].ToString())); breadcrumb.Append("</li>"); } return breadcrumb.Append("</div>").ToString(); }
public static string LoginLink(this HtmlHelper helper) { string currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"]; string currentActionName = (string)helper.ViewContext.RouteData.Values["action"]; bool isAuthenticated = helper.ViewContext.HttpContext.Request.IsAuthenticated; var sb = new StringBuilder(); if (isAuthenticated) { sb.Append("Logged in as <span>"); sb.Append(helper.ViewContext.HttpContext.User.Identity.Name); sb.Append("</span>"); } sb.Append("<div id=\"loginlink\""); if (currentControllerName.Equals("Account", StringComparison.CurrentCultureIgnoreCase) && (currentActionName.Equals("Login", StringComparison.CurrentCultureIgnoreCase) || currentActionName.Equals("Logout", StringComparison.CurrentCultureIgnoreCase))) sb.Append(" class=\"selected\">"); else sb.Append(">"); if (isAuthenticated) { sb.Append(helper.ActionLink("Logout", "Logout", "Account")); } else { sb.Append(helper.ActionLink("Login", "Logon", "Account")); } sb.Append("</div>"); return sb.ToString(); }
public static MvcHtmlString PagingNavigator(this AjaxHelper helper, int pageNum, int itemsCount, int pageSize) { StringBuilder sb = new StringBuilder(); AjaxOptions ao = new AjaxOptions {UpdateTargetId = "BooksDiv"}; if (pageNum > 0) { sb.Append(helper.ActionLink("<", "Index","Books", new { pageNum = pageNum - 1 },ao)); } else { sb.Append(HttpUtility.HtmlEncode("<")); } sb.Append(" "); int pagesCount = (int)Math.Ceiling((double)itemsCount / pageSize); if (pageNum < pagesCount - 1) { sb.Append(helper.ActionLink(">", "Index","Books", new { pageNum = pageNum + 1 },ao)); } else { sb.Append(HttpUtility.HtmlEncode(">")); } return MvcHtmlString.Create(sb.ToString()); }
/// <summary> /// The pager. /// </summary> /// <param name="helper"> /// The helper. /// </param> /// <param name="action"> /// The action. /// </param> /// <param name="pageIndex"> /// The page index. /// </param> /// <param name="pageSize"> /// The page size. /// </param> /// <param name="totalRecords"> /// The total records. /// </param> /// <returns> /// The System.String. /// </returns> public static string Pager(this HtmlHelper helper, string action, int pageIndex, int pageSize, int totalRecords) { string html = string.Empty; int pageCount = (totalRecords % pageSize == 0) ? (totalRecords / pageSize) : (totalRecords / pageSize) + 1; for (int idx = 1; idx <= pageCount; idx++) { if (idx - 1 == pageIndex) { html += idx.ToString() + " "; } else { if (idx == 1) { html += helper.ActionLink(idx.ToString(), action); } else { html += helper.ActionLink(idx.ToString(), action, new { id = idx - 1, page = idx - 1 }); } html += " "; } } return html; }
public static MvcHtmlString MenuLinkListItem( this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, bool isAdmin = false ) { string currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller"); var li = new TagBuilder("li"); if (controllerName == currentController) { li.AddCssClass("active"); } if (isAdmin) { li.InnerHtml = htmlHelper.ActionLink(linkText, actionName, controllerName, new { area = MVC.Admin.Name }, null).ToHtmlString(); } else { li.InnerHtml = htmlHelper.ActionLink(linkText, actionName, controllerName).ToHtmlString(); } return new MvcHtmlString(li.ToString()); }
public static MvcHtmlString MenuItem(this HtmlHelper html, string actionName, string controllerName,string unselectedCss,string selectedCss, string menuCaption,string tagName = "div",IDictionary<string,object> htmlAttributes = null, string permissionName = "",bool isVisible = true,object routeValues = null) { if (isVisible) { bool canUserSeeItem = false; if (!String.IsNullOrWhiteSpace(permissionName)) { //TODO : check here visibility of menu item by permission check canUserSeeItem = false; } else { canUserSeeItem = true; } if (canUserSeeItem == true) { string selectionString = String.Empty; string selectionCssClass = String.Empty; if (html.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString().Equals(controllerName, StringComparison.OrdinalIgnoreCase) && html.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString().Equals(controllerName, StringComparison.OrdinalIgnoreCase)) { selectionString = "true"; selectionCssClass = selectedCss; } else { selectionCssClass = unselectedCss; selectionString = "false"; } string itemControl = String.Empty; if (routeValues == null) { itemControl = String.Format(@" <{3} class='{2} MenuItem' data-isSelected='{1}'> {0} </{3}> ", html.ActionLink(menuCaption, actionName, controllerName), selectionString, selectionCssClass, tagName); } else { itemControl = String.Format(@" <{3} class='{2} MenuItem' data-isSelected='{1}'> {0} </{3}> ", html.ActionLink(menuCaption, actionName, controllerName,routeValues,null), selectionString, selectionCssClass, tagName); } return MvcHtmlString.Create(itemControl); } } return MvcHtmlString.Create(""); }
public static MvcHtmlString CreatePostLink(this HtmlHelper html, Thread thread) { string txt = thread.IsLocked ? "Locked" : "Create Post"; string cssClass = thread.IsLocked ? "img_link create-post-locked" : "img_link create-post"; if (thread.IsLocked) return html.ActionLink(txt, "ViewThread", "Board", new { ThreadID = thread.ThreadID }, new { @class = cssClass }); else return html.ActionLink(txt, "CreatePost", "Post", new { ThreadID = thread.ThreadID }, new { @class = cssClass }); }
public static IHtmlString MessageDetailsLink(this HtmlHelper htmlHelper, Message message) { string linkText = message.UserSender + "---------------" + message.SentAt; if (message.Unread) { return htmlHelper.ActionLink(linkText, "Respond", "MailBox", new { id = message.Id }, new {style="font-weight:bold;"}); } return htmlHelper.ActionLink(linkText, "Respond", "MailBox", new { id = message.Id }, null); }
public static MvcHtmlString MenuLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName) { var currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action"); var currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller"); if (actionName == currentAction && controllerName == currentController) { return htmlHelper.ActionLink( linkText, actionName, controllerName, null, new { @class = "active-menu" }); } return htmlHelper.ActionLink(linkText, actionName, controllerName); }
public static MvcHtmlString PageNavigator(this HtmlHelper hlp, int ItemsCoun, int PageSize, int PageNum = 0) { StringBuilder sb = new StringBuilder(); if (PageNum > 0) sb.AppendLine("<div class=\"nav-previous\">" + hlp.ActionLink("Следующие →", "Category", "Home", new { page = PageNum - 1 }, null) + "</div>"); int pgCount = (int)Math.Ceiling((double)ItemsCoun / PageSize); if (PageNum < pgCount - 1) sb.AppendLine("<div class=\"nav-next\">" + hlp.ActionLink("← Предыдущие", "Category", "Home", new { page = PageNum + 1 }, null) + "</div>"); return MvcHtmlString.Create(sb.ToString()); }
public static MvcHtmlString SubscriptionLink(this HtmlHelper html, int threadID, bool isSubscribed) { string txt = isSubscribed ? "Unsubscribe to Thread" : "Subscribe to Thread"; string cssClass = "img_link thread-subscription"; if (isSubscribed) return html.ActionLink(txt, "UnsubscribeToThread", new { ThreadID = threadID }, new { @class = cssClass }); else return html.ActionLink(txt, "SubscribeToThread", new { ThreadID = threadID }, new { @class = cssClass }); }
public static string MenuLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string activeClass, bool checkAction) { var currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action"); var currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller"); if (string.Compare(controllerName, currentController, StringComparison.OrdinalIgnoreCase) == 0 && ((!checkAction) || string.Compare(actionName, currentAction, StringComparison.OrdinalIgnoreCase) == 0)) { return htmlHelper.ActionLink(linkText, actionName, controllerName, null, new { @class = activeClass }).ToString(); } return htmlHelper.ActionLink(linkText, actionName, controllerName).ToString(); }
public static MvcHtmlString UsernameLink(this HtmlHelper html, User user, bool includeRankColor = true) { if (includeRankColor) { string colorHex = html.UsernameColor(user).ToString(); object styleObject = colorHex != string.Empty ? new { style = colorHex } : null; return html.ActionLink(user.Username, "UserProfile", "Members", new { UserNameOrID = user.UserID }, styleObject); } else return html.ActionLink(user.Username, "UserProfile", "Members", new { UserNameOrID = user.UserID }, null); }
//public string public static string MasterMenu(this HtmlHelper html, string title, string action, string controller) { if (controller.Equals(html.ViewContext.RouteData.Values["controller"] as string, StringComparison.OrdinalIgnoreCase) && action.Equals(html.ViewContext.RouteData.Values["action"] as string, StringComparison.OrdinalIgnoreCase)) { return "<li class='selected'>" + html.ActionLink(title, action, controller) + "</li>"; } else { return "<li>" + html.ActionLink(title, action, controller) + "</li>"; } }
public static MvcHtmlString MenuLink(this HtmlHelper helper, string text, string action, string controller) { var routeData = helper.ViewContext.RouteData.Values; var currentController = (string)routeData["controller"]; var currentAction = (string)routeData["action"]; if (String.Equals(action, currentAction, StringComparison.OrdinalIgnoreCase) && String.Equals(controller, currentController, StringComparison.OrdinalIgnoreCase)) { return helper.ActionLink(text, action, controller, null, new { @class = "menu-top-item-active" }); } return helper.ActionLink(text, action, controller); }
public static MvcHtmlString StationChannelLinks(this HtmlHelper helper, Silo.Domain.Entities.Station station) { if (station.Channels != null && station.Channels.Any()) { string text = String.Join(", ", station.Channels.OrderBy(x => x.TxAntAzimuth).Select(x => (int)x.TxAntAzimuth).ToArray()); return helper.ActionLink(text, "Channels", null, new { station.Id }, new { style = "text-decoration: underline" }); } else { return helper.ActionLink("New Channel", "Create", "Channel", new { stationId = station.Id }, new { @class = "btn btn-success" }); } }
public static string MenuItem(this HtmlHelper helper, string text, string action, string controller) { var route = helper.ViewContext.RequestContext.RouteData; var currentcontroller = route.GetRequiredString("controller"); var currentaction = route.GetRequiredString("action"); string menu = ""; if (currentcontroller == controller && currentaction == action) menu += "\n\t<li value=\"1\">" + helper.ActionLink(text, action, controller) + "</li>"; else menu += "\n\t<li>" + helper.ActionLink(text, action, controller) + "</li>"; return menu; }
public static MvcHtmlString MenuLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string liCssClass) { var currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action"); var currentController = htmlHelper.ViewContext.RouteData.GetRequiredString("controller"); if (actionName == currentAction && controllerName == currentController) { liCssClass += " active"; } return string.IsNullOrWhiteSpace(liCssClass) ? MvcHtmlString.Create("<li>" + htmlHelper.ActionLink(linkText, actionName, controllerName) + "</li>") : MvcHtmlString.Create("<li class=\"" + liCssClass + "\">" + htmlHelper.ActionLink(linkText, actionName, controllerName) + "</li>"); }
public static MvcHtmlString MenuLinkBootstrap(this HtmlHelper helper, string text, string action, string controller, string parameter = "") { var routeData = helper.ViewContext.RouteData.Values; var currentController = routeData["controller"]; var currentAction = routeData["action"]; if (String.Equals(action, currentAction as string, StringComparison.OrdinalIgnoreCase) && String.Equals(controller, currentController as string, StringComparison.OrdinalIgnoreCase)) { return new MvcHtmlString("<li class=\"active\">" + helper.ActionLink(text, action, controller, new { id = parameter }, null) + "</li>"); } return new MvcHtmlString("<li>" + helper.ActionLink(text, action, controller, new { id = parameter }, null) + "</li>"); }
public static MvcHtmlString AuthenticationStatus(this HtmlHelper html) { string outputString; if (HttpContext.Current.User == null || !HttpContext.Current.User.Identity.IsAuthenticated) { outputString = string.Format("<li>{0}</li> <li>{1}</li>", html.ActionLink("register", "New", "user", null, null), html.ActionLink("login", "New", "Session", null, null)); } else { outputString = string.Format("<li>{0}</li> <li>{1}</li>", html.ActionLink("dashboard", "Index", "Dashboard", null, null), html.ActionLink("logout", "Delete", "session", null, null)); } return new MvcHtmlString(outputString); }
public static IHtmlString ShowSpeakerLinks(this HtmlHelper htmlHelper, SpeakerListModel model) { var zeigen= htmlHelper.ActionLink("Zeigen", "Details", "Speaker", new { id = model.Id }, null); var sessions = htmlHelper.ActionLink("Sessions", "List", "SpeakerSession", new { speakerid = model.Id }, null); return new HtmlString(string.Format("{0} | {1}",zeigen,sessions)); }
public static MvcHtmlString HashtagLink( this HtmlHelper htmlHelper, Hashtag hashtag, bool hasMargin = false ) { var link = htmlHelper.ActionLink(hashtag.Text, MVC.Search.ActionNames.Index, MVC.Search.Name, new { hashtags = hashtag.HashtagId }, null).ToHtmlString(); if (hasMargin) { link = htmlHelper.ActionLink(hashtag.Text, MVC.Search.ActionNames.Index, MVC.Search.Name, new { hashtags = hashtag.HashtagId }, new { @class = "hashtag-link-margin" }).ToHtmlString(); } return new MvcHtmlString(link); }