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


C# Mvc.HtmlHelper类代码示例

本文整理汇总了C#中System.Web.Mvc.HtmlHelper的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper类的具体用法?C# HtmlHelper怎么用?C# HtmlHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HtmlHelper类属于System.Web.Mvc命名空间,在下文中一共展示了HtmlHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HiggsLabel

 public HiggsLabel(HtmlHelper helper, ControlBase input, string text)
     : base(helper, "label")
 {
     ForInputId = input.Id;
     Text = text;
     input.OnIdChange += MainInput_OnChangeId;
 }
开发者ID:kirkpabk,项目名称:higgs,代码行数:7,代码来源:HiggsLabel.cs

示例2: RenderFormGroupSelectElement

        public static string RenderFormGroupSelectElement(HtmlHelper html, SelectElementModel inputModel,
			LabelModel labelModel, InputType inputType)
        {
            HtmlString input = null;

            if (inputType == InputType.DropDownList)
                input = RenderSelectElement(html, inputModel, InputType.DropDownList);

            if (inputType == InputType.ListBox)
                input = RenderSelectElement(html, inputModel, InputType.ListBox);

            var label = RenderLabel(html, labelModel ?? new LabelModel
            {
                htmlFieldName = inputModel.htmlFieldName,
                metadata = inputModel.metadata,
                htmlAttributes = new {@class = "control-label"}.ToDictionary()
            });

            var fieldIsValid = true;

            if (inputModel != null)
                fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName);

            return new FormGroup(input, label, FormGroupType.TextBoxLike, fieldIsValid).ToHtmlString();
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:25,代码来源:RenderFormGroupSelectElement.cs

示例3: RenderFormGroupCustom

        public static string RenderFormGroupCustom(HtmlHelper html, FormGroupCustomModel customModel, LabelModel labelModel)
        {
            var label = RenderControl.RenderLabel(html, labelModel ?? new LabelModel
            {
                htmlFieldName = labelModel.htmlFieldName,
                metadata = labelModel.metadata,
                htmlAttributes = new { @class = "control-label" }.ToDictionary()
            });

            var htmlInput = customModel.input;

            TagBuilder wrapper = null;

            if (!string.IsNullOrEmpty(customModel.controlsElementWrapper))
            {
                wrapper = new TagBuilder(customModel.controlsElementWrapper);

                if (customModel.controlsElementWrapperAttributes != null)
                    wrapper.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(customModel.controlsElementWrapperAttributes));

                wrapper.InnerHtml = htmlInput.ToHtmlString();
            }

            HtmlString htmlString = wrapper != null
                ? new HtmlString(wrapper.ToString(TagRenderMode.Normal))
                : htmlInput;

            bool fieldIsValid = true;

            if (labelModel != null && labelModel.htmlFieldName != null)
                fieldIsValid = html.ViewData.ModelState.IsValidField(labelModel.htmlFieldName);

            return new FormGroup(htmlString, label, FormGroupType.TextBoxLike, fieldIsValid).ToHtmlString();
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:34,代码来源:RenderFormGroupCustom.cs

示例4: GenerateUrl

        private static string GenerateUrl(HtmlHelper htmlHelper, Route route, RouteValueDictionary routeValues)
        {
            //TODO: remove code dupe see UrlLinkToExtensions
            var requestCtx = htmlHelper.ViewContext.RequestContext;
            var httpCtx = requestCtx.HttpContext;

            if (routeValues != null)
            {
                foreach (var d in route.Defaults)
                {
                    if (!routeValues.ContainsKey(d.Key))
                        routeValues.Add(d.Key, d.Value);
                }
            }
            else
            {
                routeValues = route.Defaults;
            }

            VirtualPathData vpd = route.GetVirtualPath(requestCtx, routeValues);
            if (vpd == null)
                return null;

            return httpCtx.Request.ApplicationPath + vpd.VirtualPath;
        }
开发者ID:goneale,项目名称:AppAir.Web,代码行数:25,代码来源:HtmlLinkToExtensions.cs

示例5: ModelRendererBase

        protected ModelRendererBase(HtmlHelper html, object model)
        {
            this.htmlHelper = html;
            this.model = model;

            this.htmlTextWriter = new HtmlTextWriter(new StringWriter());
        }
开发者ID:dwdkls,项目名称:pizzamvc,代码行数:7,代码来源:ModelRendererBase.cs

示例6: MenuWriter

 public MenuWriter(HtmlHelper htmlHelper, Menu menu, bool nest, object attributes)
 {
     this.htmlHelper = htmlHelper;
     this.menu = menu;
     this.nest = nest;
     this.attributes = attributes;
 }
开发者ID:somlea-george,项目名称:sutekishop,代码行数:7,代码来源:MenuWriter.cs

示例7: AddNavigationNode

        public static string AddNavigationNode(HtmlHelper htmlHelper, NavigationNode node)
        {
            StringBuilder nodeOutput = new StringBuilder();

            if (node.Children.Count == 0)
            {
                nodeOutput.Append("<li>");
            }
            else
            {
                nodeOutput.Append("<li class=\"dropdown\">");
            }

            if (node.Children.Count == 0)
            {
                nodeOutput.Append(htmlHelper.ActionLink(node.Name, node.Action, node.Controller).ToString());
            }
            else
            {
                nodeOutput.Append(string.Format(@"<a href=""#"" class=""dropdown-toggle"" data-toggle=""dropdown"">{0}<b class=""caret""></b></a>", node.Name));
                nodeOutput.Append(AddSubMenu(htmlHelper, node.Children));
            }

            nodeOutput.Append("</li>");

            return nodeOutput.ToString();
        }
开发者ID:modulexcite,项目名称:framework-1,代码行数:27,代码来源:NavigationExtensions.cs

示例8: ButtonTests

        public ButtonTests()
        {
            var viewContext = new Mock<ViewContext>();
            var viewDataContainer = new Mock<IViewDataContainer>();

            _html = new HtmlHelper(viewContext.Object, viewDataContainer.Object);
        }
开发者ID:ebashmakov,项目名称:Mvc.Html.Bootstrap,代码行数:7,代码来源:ButtonTests.cs

示例9: Create

 public static HtmlHelper Create()
 {
     var viewContext = new ViewContext();
     var dataContainer = new Mock<IViewDataContainer>();
     var htmlHelper = new HtmlHelper(viewContext, dataContainer.Object);
     return htmlHelper;
 }
开发者ID:jgsteeler,项目名称:MvcReportViewer,代码行数:7,代码来源:HtmlHelperFactory.cs

示例10: GenerateTab

        public string GenerateTab(ref HtmlHelper html, string text, string value)
        {
            var routeDataValues = html.ViewContext.RequestContext.RouteData.Values;

            RouteValueDictionary pageLinkValueDictionary = new RouteValueDictionary { { Param, value } };

            if (html.ViewContext.RequestContext.HttpContext.Request.QueryString["search"] != null)
                pageLinkValueDictionary.Add("search", html.ViewContext.RequestContext.HttpContext.Request.QueryString["search"]);

            if (!pageLinkValueDictionary.ContainsKey("id") && routeDataValues.ContainsKey("id"))
                pageLinkValueDictionary.Add("id", routeDataValues["id"]);

            // To be sure we get the right route, ensure the controller and action are specified.
            if (!pageLinkValueDictionary.ContainsKey("controller") && routeDataValues.ContainsKey("controller"))
                pageLinkValueDictionary.Add("controller", routeDataValues["controller"]);

            if (!pageLinkValueDictionary.ContainsKey("action") && routeDataValues.ContainsKey("action"))
                pageLinkValueDictionary.Add("action", routeDataValues["action"]);

            // 'Render' virtual path.
            var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(html.ViewContext.RequestContext, pageLinkValueDictionary);

            if (virtualPathForArea == null)
                return null;

            var stringBuilder = new StringBuilder("<li");

            if (value == CurrentValue)
                stringBuilder.Append(" class=active");

            stringBuilder.AppendFormat("><a href={0}>{1}</a></li>", virtualPathForArea.VirtualPath, text);

            return stringBuilder.ToString();
        }
开发者ID:revolutionaryarts,项目名称:wewillgather,代码行数:34,代码来源:TabHelper.cs

示例11: RibbonAppMenu

 public RibbonAppMenu(HtmlHelper helper, string id, string title, string iconUrl = null)
     : base(helper)
 {
     Id = id;
     Title = title;
     IconUrl = iconUrl;
 }
开发者ID:kirkpabk,项目名称:higgs,代码行数:7,代码来源:RibbonAppMenu.cs

示例12: RenderFormGroupRadioButton

        public static string RenderFormGroupRadioButton(HtmlHelper html, RadioButtonModel inputModel, LabelModel labelModel)
        {
            var validationMessage = "";
            var radioType = "form-icon";

            if (inputModel.displayValidationMessage)
            {
                var validation = html.ValidationMessage(inputModel.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, inputModel.validationMessageStyle).ToHtmlString();
            }

            if (labelModel == null && inputModel.RadioType != InputRadioCheckBoxType._NotSet)
                radioType = inputModel.RadioType.ToName();

            var label = RenderLabel(html, labelModel ?? new LabelModel
            {
                htmlFieldName = inputModel.htmlFieldName,
                metadata = inputModel.metadata,
                innerInputType = InputType.Radio,
                innerInputModel = inputModel,
                innerValidationMessage = validationMessage,
                htmlAttributes = new {@class = $"form-radio {radioType} form-text"}.ToDictionary()
            });

            var fieldIsValid = true;

            if (inputModel != null)
                fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName);

            return new FormGroup(null, label, FormGroupType.CheckBoxLike, fieldIsValid).ToHtmlString();
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:31,代码来源:RenderFormGroupRadioButton.cs

示例13: Create

 /// <summary>
 /// Create a new HtmlHelper with a fake context and container
 /// </summary>
 /// <returns>HtmlHelper</returns>
 public static HtmlHelper Create()
 {
     var vc = new ViewContext();
     vc.HttpContext = new FakeHttpContext();
     var html = new HtmlHelper(vc, new FakeViewDataContainer());
     return html;
 }
开发者ID:gabrielgreen,项目名称:FluentHtmlHelpers,代码行数:11,代码来源:HtmlHelperFactory.cs

示例14: Grid_GridSettingsIsNull_EmptyHtmlString

        public void Grid_GridSettingsIsNull_EmptyHtmlString()
        {
            var html = new HtmlHelper(new ViewContext(), new ViewDataContainer());
            MvcHtmlString grid = html.Grid(null);

            Assert.AreEqual(string.Empty, grid.ToString());
        }
开发者ID:JeyKip,项目名称:MvcGrid,代码行数:7,代码来源:MvcGridTest.cs

示例15: RenderMainNav_RendersTheRootNodes

 public void RenderMainNav_RendersTheRootNodes()
 {
     var mockContainer = new Mock<IViewDataContainer>();
     var helper = new HtmlHelper( new ViewContext(), mockContainer.Object );
     string result = helper.RenderMainNav( "Admin", new { @class = "myNav", id = "menu" } );
     Assert.AreEqual( "<ul  class='myNav'  id='menu' ><li><a href='/Home/Index' title=HOME>HOME</a></li>\r\n<li><a href='/Dashboard/Index' title=Dashboard>Dashboard</a></li>\r\n<li><a href='/Administrator/Stats' title=My Stats>My Stats</a></li>\r\n</ul>", result );
 }
开发者ID:minhajuddin,项目名称:sitemaplite,代码行数:7,代码来源:HtmlHelperExtensionTests.cs


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