本文整理汇总了C#中this.ActionLink方法的典型用法代码示例。如果您正苦于以下问题:C# this.ActionLink方法的具体用法?C# this.ActionLink怎么用?C# this.ActionLink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.ActionLink方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProductActions
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;
}
示例2: DisplayNameForSort
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);
}
}
示例3: MenuLink
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);
}
示例4: PagingNavigator
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());
}
示例5: BlogPager
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();
}
示例6: MenuItem
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());
}
示例7: PrettyJoin
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);
}
示例8: MenuItem
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());
}
示例9: SiteMenu
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());
}
示例10: BuildBreadcrumbNavigation
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();
}
示例11: LoginLink
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();
}
示例12: Pager
/// <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;
}
示例13: MenuLinkListItem
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());
}
示例14: MenuItem
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("");
}
示例15: CreatePostLink
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 });
}