本文整理汇总了C#中UrlHelper.Action方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.Action方法的具体用法?C# UrlHelper.Action怎么用?C# UrlHelper.Action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.Action方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MenuItemCheveron
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());
}
示例2: ActionImage
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);
}
示例3: ActionLinkImage
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));
}
示例4: Tab
/// <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));
}
示例5: ActionLinkSelected
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);
}
示例6: ActionLink
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;
}
示例7: LinkEntity
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);
}