• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Mvc.HtmlHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: RenderCheckBoxCustom

        public static HtmlString RenderCheckBoxCustom(HtmlHelper html, CheckBoxModel model)
        {
            var fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName);

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            ModelState modelState;

            if (html.ViewData.ModelState.TryGetValue(fullHtmlFieldName, out modelState))
            {
                if (modelState.Errors.Count > 0)
                    model.htmlAttributes.AddOrMergeCssClass("class", "input-validation-error");

                if (modelState.Value != null && ((string[]) modelState.Value.RawValue).Contains(model.value.ToString()))
                    model.isChecked = true;
            }

            var input = new TagBuilder("input");
            input.Attributes.Add("type", "checkbox");
            input.Attributes.Add("name", fullHtmlFieldName);
            input.Attributes.Add("id", model.id);
            input.Attributes.Add("value", model.value.ToString());

            if (model.isChecked)
                input.Attributes.Add("checked", "checked");

            if (model.isDisabled)
                input.Attributes.Add("disabled", "disabled");

            input.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes());

            return new HtmlString(input.ToString(TagRenderMode.SelfClosing));
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:33,代码来源:RenderCheckBoxCustom.cs


示例17: ViewComponentFactory

        public ViewComponentFactory(HtmlHelper htmlHelper, IUrlGenerator urlGenerator)
            : base(htmlHelper.ViewContext)
        {
            Guard.IsNotNull(urlGenerator, "urlGenerator");

            this.urlGenerator = urlGenerator;
        }
开发者ID:timbooker,项目名称:telerikaspnetmvc,代码行数:7,代码来源:ViewComponentFactory.cs


示例18: GetFlashMessages

 private static IDictionary<string, MvcHtmlString> GetFlashMessages(HtmlHelper helper, string sessionKey)
 {
     sessionKey = "Flash." + sessionKey;
     return (helper.ViewContext.TempData[sessionKey] != null
                 ? (IDictionary<string, MvcHtmlString>)helper.ViewContext.TempData[sessionKey]
                 : new Dictionary<string, MvcHtmlString>());
 }
开发者ID:briansalato,项目名称:Irving,代码行数:7,代码来源:FlashHelper.cs


示例19: ComponentPresentations

        public MvcHtmlString ComponentPresentations(IPage tridionPage, HtmlHelper htmlHelper, string[] includeComponentTemplate, string includeSchema)
        {
            LoggerService.Information(">>ComponentPresentations", LoggingCategory.Performance);
            StringBuilder sb = new StringBuilder();
            foreach (IComponentPresentation cp in tridionPage.ComponentPresentations)
            {
                if (includeComponentTemplate != null && !MustInclude(cp.ComponentTemplate, includeComponentTemplate))
                    continue;
                if (cp.Component != null && (!string.IsNullOrEmpty(includeSchema)) && !MustInclude(cp.Component.Schema, includeSchema))
                    continue;
                // Quirijn: if a component presentation was created by a non-DD4T template, its output was stored in RenderedContent
                // In that case, we simply write it out
                // Note that this type of component presentations cannot be excluded based on schema, because we do not know the schema
                if (!string.IsNullOrEmpty(cp.RenderedContent))
                    return new MvcHtmlString(cp.RenderedContent);
                LoggerService.Debug("rendering cp {0} - {1}", LoggingCategory.Performance, cp.Component.Id, cp.ComponentTemplate.Id);
               
                cp.Page = tridionPage;
                LoggerService.Debug("about to call RenderComponentPresentation", LoggingCategory.Performance);
                if (ShowAnchors)
                    sb.Append(string.Format("<a id=\"{0}\"></a>", DD4T.Utils.TridionHelper.GetLocalAnchor(cp)));
                sb.Append(RenderComponentPresentation(cp, htmlHelper));
                LoggerService.Debug("finished calling RenderComponentPresentation", LoggingCategory.Performance);

            }
            LoggerService.Information("<<ComponentPresentations", LoggingCategory.Performance);
            return MvcHtmlString.Create(sb.ToString());
        }
开发者ID:flaithbheartaigh,项目名称:dynamic-delivery-4-tridion,代码行数:28,代码来源:DefaultComponentPresentationRenderer.cs


示例20: Setup

		public void Setup()
		{
			// WikiController setup (use WikiController as it's the one typically used by views)
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;
			_pageRepository = _container.PageRepository;
			_pluginFactory = _container.PluginFactory;
			_settingsService = _container.SettingsService;
			_userService = _container.UserService;
			_historyService = _container.HistoryService;
			_pageService = _container.PageService;

			_wikiController = new WikiController(_applicationSettings, _userService, _pageService, _context, _settingsService);
			_wikiController.SetFakeControllerContext("~/wiki/index/1");

			// HtmlHelper setup
			var viewDataDictionary = new ViewDataDictionary();
			_viewContext = new ViewContext(_wikiController.ControllerContext, new Mock<IView>().Object, viewDataDictionary, new TempDataDictionary(), new StringWriter());
			var mockViewDataContainer = new Mock<IViewDataContainer>();
			mockViewDataContainer.Setup(v => v.ViewData).Returns(viewDataDictionary);

			_htmlHelper = new HtmlHelper(_viewContext, mockViewDataContainer.Object);
		}
开发者ID:RyanGroom,项目名称:roadkill,代码行数:25,代码来源:HtmlHelperExtensionTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mvc.JsonResult类代码示例发布时间:2022-05-26
下一篇:
C# Mvc.HandleErrorInfo类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap