本文整理汇总了C#中HtmlHelper.ActionLink方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.ActionLink方法的具体用法?C# HtmlHelper.ActionLink怎么用?C# HtmlHelper.ActionLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.ActionLink方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: buildActionLink
private static string buildActionLink(HtmlHelper helper, string linkText, int pageParam)
{
if ( helper.ViewContext.HttpContext.Request.QueryString.HasKeys() ) {
string sort = helper.ViewContext.HttpContext.Request.QueryString["Sort"];
return helper.ActionLink(linkText,
helper.ViewContext.RouteData.Values["action"].ToString(), new { SortExpression = sort, Page = pageParam }).ToString();
}
else {
return helper.ActionLink(linkText,
helper.ViewContext.RouteData.Values["action"].ToString(), new { Page = pageParam }).ToString();
}
}
示例2: ToNavigation
public static MvcHtmlString ToNavigation(this IEnumerable<cms_Categories> cmsCategories, HtmlHelper htmlHelper, int level = 0)
{
StringBuilder builder = new StringBuilder();
if(level == 0)
{
builder.Append(string.Format(@"<ul id=""nav-sidebox"" class=""category-items"">"));
}
else
{
builder.Append(string.Format(@"<ul class=""navigation-0a"" style=""width: 250px !important;"">"));
}
foreach (var cmsCategory in cmsCategories)
{
builder.Append(string.Format(@"<li class='level{0} subcatemenu'>", level));
builder.Append(htmlHelper.ActionLink(cmsCategory.Title, "GuestCmsNewsIndex", new { categoryID = cmsCategory.ID }));
if (cmsCategory.cms_Categories1 != null && cmsCategory.cms_Categories1.Count > 0)
{
builder.Append(cmsCategory.cms_Categories1.ToNavigation(htmlHelper, level + 1).ToString());
}
builder.Append("</li>");
}
builder.Append("</ul>");
return new MvcHtmlString(builder.ToString());
}
示例3: EntryInfoLink
public static MvcHtmlString EntryInfoLink(this BlogEntry entry, HtmlHelper htmlHelper)
{
if (entry == null)
{
throw new ArgumentNullException("entry");
}
return htmlHelper.ActionLink(entry.Name + " - " + entry.PostDateTimeUtc.ToUserDateTimeString(htmlHelper), "Index", new { blogUrlName = entry.Blog.UrlName, blogEntryUrlName = entry.UrlName });
}
示例4: CreatorActionLink
public static string CreatorActionLink(HtmlView view, ViewContext context, Match linkMatch)
{
var linkAttributes = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
MatchCollection linkAttributeMatches = RegularExpressions.AttributeNameValue.Matches(linkMatch.Value);
foreach (Match linkAttributeMatch in linkAttributeMatches)
{
string attributeName = linkAttributeMatch.Groups[1].Value.Trim();
if (String.Equals("routeValues", attributeName, StringComparison.OrdinalIgnoreCase) ||
String.Equals("htmlAttributes", attributeName, StringComparison.OrdinalIgnoreCase))
{
linkAttributes[attributeName] = DeserializeObjectAsDictionary(linkAttributeMatch.Groups[2].Value);
}
else
{
linkAttributes[attributeName] = linkAttributeMatch.Groups[2].Value.Trim();
}
}
object action, controller, routeValues, htmlAttributes;
linkAttributes.TryGetValue("action", out action);
linkAttributes.TryGetValue("controller", out controller);
if (linkAttributes.TryGetValue("routeValues", out routeValues) && routeValues is IDictionary<string, object>)
{
routeValues = new RouteValueDictionary((IDictionary<string, object>) routeValues);
}
else
{
routeValues = null;
}
if (!linkAttributes.TryGetValue("htmlAttributes", out htmlAttributes) || !(htmlAttributes is IDictionary<string, object>))
{
htmlAttributes = null;
}
string value = linkMatch.Groups[2].Value;
if (IsNullOrEmpty(value))
{
value = "action link";
}
var helper = new HtmlHelper(context, view);
string link = helper.ActionLink(ValueToken,
action as string,
controller as string,
(RouteValueDictionary) routeValues,
(IDictionary<string, object>) htmlAttributes).ToHtmlString();
return link.Replace(ValueToken, value);
}
示例5: GenerateNavigationFor35Or30
private static MvcHtmlString GenerateNavigationFor35Or30(HtmlHelper htmlHelper, Language language, string version)
{
var builder = new StringBuilder();
builder.AppendLine("<ul class='nav navbar-nav'>");
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Getting started", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "start/getting-started" }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Indexes", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "indexes/what-are-indexes" }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Transformers", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "transformers/what-are-transformers" }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Client API", MVC.Docs.ActionNames.Client, MVC.Docs.Name, new { language = language, version = version }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Server", MVC.Docs.ActionNames.Server, MVC.Docs.Name, new { language = language, version = version }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Studio", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "studio/accessing-studio" }, null)));
builder.AppendLine("<li class='dropdown'>");
builder.AppendLine("<a href='#' class='dropdown-toggle' data-toggle='dropdown'>Other <span class='caret'></span></a>");
builder.AppendLine("<ul class='dropdown-menu' role='menu'>");
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Samples", MVC.Docs.ActionNames.Samples, MVC.Docs.Name, new { language = language, version = version }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Glossary", MVC.Docs.ActionNames.Glossary, MVC.Docs.Name, new { language = language, version = version }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Users Issues", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = version, key = "users-issues/azure-router-timeout" }, null)));
builder.AppendLine("</ul>");
builder.AppendLine("</li>");
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("File System", MVC.Docs.ActionNames.FileSystem, MVC.Docs.Name, new { language = language, version = version, key = "file-system/what-is-ravenfs" }, null)));
builder.AppendLine("</ul>");
return new MvcHtmlString(builder.ToString());
}
示例6: RenderDate
private static void RenderDate(Post post, HtmlTextWriter writer, HtmlHelper helper)
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, "date");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
string displayDate = post.PublicationDate.ToString("d MMMM, yyyy");
writer.Write(helper.ActionLink(displayDate, "Load", "Post",
new
{
year = post.PublicationDate.Year,
month = post.PublicationDate.Month,
day = post.PublicationDate.Day,
slug = post.Slug
},
new { }));
writer.RenderEndTag(); //div.date
}
示例7: Index
//
// GET: /Search/
public ActionResult Index(SearchViewModel criteria)
{
var searchViewModel = new SearchViewModel()
{
Query = criteria.Query
};
if (!criteria.Query.IsNullOrEmpty())
{
var htmlHelper = new HtmlHelper(new ViewContext(this.ControllerContext, new WebFormView(this.ControllerContext, "fake"), new ViewDataDictionary(), new TempDataDictionary(), new StringWriter()), new ViewPage());
var found = default(List<ISearchResult>);
try
{
found = this.searcher.Search(criteria.Query).ToList();
}
catch(Exception ex)
{
// just lof the exception
ErrorSignal.FromCurrentContext().Raise(ex);
// and return empty result set
found = new List<ISearchResult>();
}
var communitiesFound = found.OfType<CommunitySearchResult>().ToList();
var communitiesIdsFound = communitiesFound.Select(r => r.CommunityId).ToList();
var communities = this.repos.Communities.Where(c => communitiesIdsFound.Contains(c.CommunityId)).ToList();
searchViewModel.Result =
from r in communitiesFound
let community = communities.First(c => c.CommunityId == r.CommunityId)
select new SearchResultEntryViewModel
{
Category = "community",
Link = htmlHelper.ActionLink(community.Name, "Details", "Community", null, null, r.ContentId, new { id = community.UrlId }, null).ToString(),
Fragments = r.Fragments
};
}
return View(searchViewModel);
}
示例8: Link
public virtual MvcHtmlString Link(HtmlHelper htmlHelper)
{
if (ContentId == 0) return MvcHtmlString.Empty;
return htmlHelper.ActionLink<CmsController>(c => c.Index(UrlName), Name);
}
示例9: ThemeBreadcrumb
protected MvcHtmlString ThemeBreadcrumb(HtmlHelper htmlHelper, int? clientId, Theme theme, bool ShowAsLink = false)
{
RouteValueDictionary routeData = null;
string name = "(unknown)";
bool showLink = false;
if (theme != null)
{
if (theme.ThemeId == 0)
{
name = "New";
}
else
{
showLink = ShowAsLink;
routeData = new RouteValueDictionary(new { id = theme.ThemeId });
name = "'" + theme.Name + "' [" + theme.ThemeId + "]";
}
}
return new MvcHtmlString(
ThemesBreadcrumb(htmlHelper, clientId, true).ToHtmlString()
+ " -> "
+ (showLink ? htmlHelper.ActionLink(name, "Details", "ThemeSysAdmin", routeData, null).ToHtmlString() : name)
);
}
示例10: TopBreadcrumb
protected MvcHtmlString TopBreadcrumb(HtmlHelper htmlHelper, bool ShowAsLink = false)
{
if (ShowAsLink)
{
return htmlHelper.ActionLink("System Admin", "Index", "SystemAdmin");
}
else
{
return new MvcHtmlString("System Admin");
}
}
示例11: ValueListItemBreadcrumb
protected MvcHtmlString ValueListItemBreadcrumb(HtmlHelper htmlHelper, ValueListItem valueListItem, bool ShowAsLink = false)
{
RouteValueDictionary routeData = null;
string name = "(unknown)";
bool showLink = false;
if (valueListItem != null)
{
if (valueListItem.ValueListItemId == 0)
{
name = "New";
}
else
{
showLink = ShowAsLink;
routeData = new RouteValueDictionary(new { id = valueListItem.ValueListItemId });
name = "'" + valueListItem.Name + "' [" + valueListItem.ValueListItemId + "]";
}
}
return new MvcHtmlString(
ValueListItemsBreadcrumb(htmlHelper, valueListItem.ValueList, true).ToHtmlString()
+ " -> "
+ (showLink ? htmlHelper.ActionLink(name, "ListItemDetails", "ValueListSysAdmin", routeData, null).ToHtmlString() : name)
);
}
示例12: StoreFrontBreadcrumb
protected MvcHtmlString StoreFrontBreadcrumb(HtmlHelper htmlHelper, int? clientId, StoreFront storeFront, bool ShowAsLink = false)
{
RouteValueDictionary routeData = null;
string name = "(unknown)";
bool showLink = false;
if (storeFront != null)
{
if (storeFront.StoreFrontId == 0)
{
name = "New";
}
else
{
showLink = ShowAsLink;
routeData = new RouteValueDictionary(new { id = storeFront.StoreFrontId });
StoreFrontConfiguration config = storeFront.CurrentConfigOrAny();
name = (config == null ? "id [" + storeFront.StoreFrontId + "]" : "'" + config.Name + "' [" + storeFront.StoreFrontId + "]");
}
}
return new MvcHtmlString(
StoreFrontsBreadcrumb(htmlHelper, clientId, true).ToHtmlString()
+ " -> "
+ (showLink ? htmlHelper.ActionLink(name, "Details", "StoreFrontSysAdmin", routeData, null).ToHtmlString() : name)
);
}
示例13: GenerateNavigationFor10
private static MvcHtmlString GenerateNavigationFor10(HtmlHelper htmlHelper, Language language)
{
var builder = new StringBuilder();
builder.AppendLine("<ul class='nav navbar-nav'>");
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Intro", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "intro" }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Theory", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "theory" }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink(".NET Client API", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "client-api" }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("HTTP API", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "http-api" }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Server side", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "server" }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Studio", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "studio" }, null)));
builder.AppendLine("<li class='dropdown'>");
builder.AppendLine("<a href='#' class='dropdown-toggle' data-toggle='dropdown'>Other <span class='caret'></span></a>");
builder.AppendLine("<ul class='dropdown-menu' role='menu'>");
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("Appendixes", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "appendixes" }, null)));
builder.AppendLine(string.Format("<li>{0}</li>", htmlHelper.ActionLink("FAQ", MVC.Docs.ActionNames.Articles, MVC.Docs.Name, new { language = language, version = "1.0", key = "faq" }, null)));
builder.AppendLine("</ul>");
builder.AppendLine("</li>");
builder.AppendLine("</ul>");
return new MvcHtmlString(builder.ToString());
}
示例14: HtmlHelperWorksOnItsOwn
public void HtmlHelperWorksOnItsOwn()
{
var viewContext = MakeViewContext("helpers");
var html = new HtmlHelper(viewContext, new ViewDataContainer { ViewData = viewContext.ViewData });
var link = html.ActionLink("hello", "world");
response.Write(link);
//mocks.VerifyAll();
Assert.AreEqual("<a href=\"/Home/world\">hello</a>", link);
}
示例15: UserProfileBreadcrumb
protected MvcHtmlString UserProfileBreadcrumb(HtmlHelper htmlHelper, int? clientId, int? storeFrontId, UserProfile userProfile, bool ShowAsLink = false)
{
RouteValueDictionary routeData = null;
string name = "(unknown)";
bool showLink = false;
if (userProfile != null)
{
if (userProfile.UserProfileId == 0)
{
name = "New";
}
else
{
showLink = ShowAsLink;
routeData = new RouteValueDictionary(new { id = userProfile.UserProfileId });
name = "'" + userProfile.FullName + "' <" + userProfile.Email + "> [" + userProfile.UserProfileId + "]";
}
}
return new MvcHtmlString(
UserProfilesBreadcrumb(htmlHelper, clientId, storeFrontId, true).ToHtmlString()
+ " -> "
+ (showLink ? htmlHelper.ActionLink(name, "Details", "UserProfileSysAdmin", routeData, null).ToHtmlString() : name.ToHtml())
);
}