当前位置: 首页>>代码示例>>C#>>正文


C# UrlHelper.Action方法代码示例

本文整理汇总了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());
        }
开发者ID:sg0193,项目名称:Waterforafrica,代码行数:28,代码来源:HtmlExtensions.cs

示例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);
        }
开发者ID:anlugifa,项目名称:BootWrapper,代码行数:25,代码来源:MvcHtmlExtentions.cs

示例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));
        }
开发者ID:wduffy,项目名称:Toltech.Mvc,代码行数:11,代码来源:ActionLinkImage.cs

示例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));
        }
开发者ID:chrcar01,项目名称:SimpleTasks,代码行数:22,代码来源:HtmlHelperExtensions.cs

示例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);
        }
开发者ID:wduffy,项目名称:Toltech.Mvc,代码行数:21,代码来源:ActionLinkSelected.cs

示例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;
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:24,代码来源:PagerShapes.cs

示例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);
        }
开发者ID:anlugifa,项目名称:BootWrapper,代码行数:14,代码来源:MvcHtmlExtentions.cs


注:本文中的UrlHelper.Action方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。