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


C# HtmlHelper类代码示例

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


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

示例1: BootstrapActionLink

 public BootstrapActionLink(HtmlHelper html, string linkText, ActionResult result)
 {
     this.html = html;
     this._linkText = linkText;
     this._result = result;
     this._actionTypePassed = ActionTypePassed.HtmlActionResult;
 }
开发者ID:joypipi,项目名称:TwitterBootstrapMvc,代码行数:7,代码来源:BootstrapActionLink.cs

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

示例3: TabStripCreated

 public TabStripCreated(TabFactory itemFactory, string tabStripName, HtmlHelper html, object model = null)
 {
     this.TabStripName = tabStripName;
     this.Html = html;
     this.Model = model;
     this.ItemFactory = itemFactory;
 }
开发者ID:JeffersonNascimento,项目名称:SmartStoreNET,代码行数:7,代码来源:TabStripCreated.cs

示例4: BootstrapRadioButton

 public BootstrapRadioButton(HtmlHelper html, string htmlFieldName, object value, ModelMetadata metadata)
 {
     this.html = html;
     this._model.htmlFieldName = htmlFieldName;
     this._model.value = value;
     this._model.metadata = metadata;
 }
开发者ID:joypipi,项目名称:TwitterBootstrapMvc,代码行数:7,代码来源:BootstrapRadioButton.cs

示例5: ListBox

 public ListBox(HtmlHelper html, string htmlFieldName, IEnumerable<SelectListItem> selectList, ModelMetadata metadata)
 {
     this.html = html;
     this._model.htmlFieldName = htmlFieldName;
     this._model.selectList = selectList;
     this._model.metadata = metadata;
 }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:7,代码来源:ListBox.cs

示例6: WriterScope

        /// <summary>
        /// Creates new instance of scope, here writer is replaced
        /// </summary>
        /// <param name="helper">Helper where writer shoud be replaced</param>
        /// <param name="writer">Writer to use in place</param>
        public WriterScope(HtmlHelper helper, TextWriter writer)
        {
            _helper = helper;
            _original = _helper.ViewContext.Writer;

            _helper.ViewContext.Writer = writer;
        }
开发者ID:knstntn,项目名称:NedoCms,代码行数:12,代码来源:WriterScope.cs

示例7: WritesExpectedCollectionIndexHiddenInput_WhenThereIsAnIndexInRequestData

            public void WritesExpectedCollectionIndexHiddenInput_WhenThereIsAnIndexInRequestData()
            {
                const string collectionName = "CollectionName";
                var index0 = Guid.NewGuid();
                var index1 = Guid.NewGuid();
                var indexes = string.Format("{0},{1}", index0, index1);
                var httpContext = new Mock<HttpContextBase>();
                var httpContextItems = new Dictionary<string, object>();
                httpContext.Setup(p => p.Items).Returns(httpContextItems);

                var httpRequest = new Mock<HttpRequestBase>();
                httpRequest.Setup(i => i[It.Is<string>(s => s == string.Format("{0}.index", collectionName))])
                    .Returns(indexes);
                httpContext.Setup(p => p.Request).Returns(httpRequest.Object);

                var viewContext = new ViewContext();
                var writer = new StringWriter();
                viewContext.Writer = writer;

                var html = new HtmlHelper(viewContext, new FakeViewDataContainer());
                viewContext.HttpContext = httpContext.Object;

                using (var result = html.BeginCollectionItem(collectionName))
                {
                    Assert.That(result, Is.Not.Null);
                }

                var text = writer.ToString();
                Assert.That(text,
                            Is.Not.Null
                              .And.Not.Empty
                              .And.StringStarting(string.Format(@"<input type=""hidden"" name=""{0}.index"" autocomplete=""off"" value=""{1}"" />", collectionName, index0)));
            }
开发者ID:hazzik,项目名称:BeginCollectionItem,代码行数:33,代码来源:HtmlPrefixScopeExtensionsFacts.cs

示例8: RenderSitecorePlaceHolder

        public static string RenderSitecorePlaceHolder(string key)
        {
            var sublayoutId = GetSublayoutIdFromPlaceHolder(Sitecore.Context.Item[Sitecore.FieldIDs.LayoutField], key);
            if (!string.IsNullOrEmpty(sublayoutId))
            {
                var layoutItem = Sitecore.Context.Database.GetItem(ID.Parse(sublayoutId));
                var controllerName = layoutItem.Fields["Controller"].Value;
                var actionName = layoutItem.Fields["Action"].Value;

                HttpContext.Current.RewritePath(string.Concat("/", controllerName, "/", actionName));

                RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
                if (routeData != null)
                {
                    var factory = new ControllerFactory();
                    var httpContextBase = new HttpContextWrapper(HttpContext.Current);
                    var context = new RequestContext(httpContextBase, routeData);
                    Type type = factory.GetController(context, controllerName);

                    if (type != null)
                    {
                        var controller = (Controller)factory.GetController(context, type);

                        var controllerContext = new ControllerContext(httpContextBase, routeData, controller);
                        var viewContext = new ViewContext(controllerContext, new FakeView(), controller.ViewData, controller.TempData, TextWriter.Null);

                        var helper = new HtmlHelper(viewContext, new ViewPage());

                        return helper.Action(actionName, controllerName).ToHtmlString();
                    }
                }
                HttpContext.Current.RewritePath("default.aspx");
            }
            return "";
        }
开发者ID:bplasmeijer,项目名称:SitecoreMVC,代码行数:35,代码来源:RazorControl.cs

示例9: GetSelectListItems

        public static IEnumerable<SelectListItem> GetSelectListItems(HtmlHelper html, ISelectListBuilder dropDownList, string expressionText)
        {
            string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText);

            bool flag = false;

            IEnumerable<SelectListItem> selectList = dropDownList.SelectList();
            bool allowMultiple = dropDownList.Attr("multiple") == "multiple";

            if (selectList == null)
            {
                selectList = html.GetSelectListItemsFromViewData(expressionText);
                flag = true;
            }
            object defaultValue = allowMultiple ? html.GetModelStateValue(fullHtmlFieldName, typeof(string[])) : html.GetModelStateValue(fullHtmlFieldName, typeof(string));
            if (!flag && defaultValue == null && !String.IsNullOrEmpty(expressionText))
            {
                defaultValue = html.ViewData.Eval(expressionText);
            }
            if (defaultValue != null)
            {
                selectList = GetSelectListWithDefaultValue(selectList, defaultValue, allowMultiple);
            }
            return selectList;
        }
开发者ID:isannn,项目名称:Build.Mvc,代码行数:25,代码来源:SelectListHelper.cs

示例10: RenderComponentPresentations

        public static MvcHtmlString RenderComponentPresentations(HtmlHelper helper, string[] byComponentTemplate, string bySchema, IComponentPresentationRenderer renderer)
        {
            _logger.Information(">>RenderComponentPresentations", LoggingCategory.Performance);
            IComponentPresentationRenderer cpr = renderer;
            IPage page = null;
            if (helper.ViewData.Model is IPage)
            {
                page = helper.ViewData.Model as IPage;
            }
            else
            {
                try
                {
                    page = helper.ViewContext.Controller.ViewBag.Page;
                }
                catch
                {
                    return new MvcHtmlString("<!-- RenderComponentPresentations can only be used if the model is an instance of IPage or if there is a Page property in the viewbag with type IPage -->");
                }
            }

            if (renderer == null)
            {
                _logger.Debug("about to create DefaultComponentPresentationRenderer", LoggingCategory.Performance);
                renderer = _renderer;
                _logger.Debug("finished creating DefaultComponentPresentationRenderer", LoggingCategory.Performance);
            }

            _logger.Debug("about to call renderer.ComponentPresentations", LoggingCategory.Performance);
            MvcHtmlString output = renderer.ComponentPresentations(page, helper, byComponentTemplate, bySchema);
            _logger.Debug("finished calling renderer.ComponentPresentations", LoggingCategory.Performance);
            _logger.Information("<<RenderComponentPresentations", LoggingCategory.Performance);

            return output;
        }
开发者ID:dd4t,项目名称:DD4T.MVC,代码行数:35,代码来源:TridionHelper.cs

示例11: RenderEntity

 /// <summary>
 /// Render an entity (Component Presentation)
 /// </summary>
 /// <param name="item">The Component Presentation object</param>
 /// <param name="helper">The HTML Helper</param>
 /// <param name="containerSize">The size of the containing element (in grid units)</param>
 /// <param name="excludedItems">A list of view names, if the Component Presentation maps to one of these, it is skipped.</param>
 /// <returns>The rendered content</returns>
 public override MvcHtmlString RenderEntity(object item, HtmlHelper helper, int containerSize = 0, List<string> excludedItems = null)
 {
     var cp = item as IComponentPresentation;
     var mvcData = ContentResolver.ResolveMvcData(cp);
     if (cp != null && (excludedItems == null || !excludedItems.Contains(mvcData.ViewName)))
     {
         var parameters = new RouteValueDictionary();
         int parentContainerSize = helper.ViewBag.ContainerSize;
         if (parentContainerSize == 0)
         {
             parentContainerSize = SiteConfiguration.MediaHelper.GridSize;
         }
         if (containerSize == 0)
         {
             containerSize = SiteConfiguration.MediaHelper.GridSize;
         }
         parameters["containerSize"] = (containerSize * parentContainerSize) / SiteConfiguration.MediaHelper.GridSize;
         parameters["entity"] = cp;
         parameters["area"] = mvcData.ControllerAreaName;
         foreach (var key in mvcData.RouteValues.Keys)
         {
             parameters[key] = mvcData.RouteValues[key];
         }
         MvcHtmlString result = helper.Action(mvcData.ActionName, mvcData.ControllerName, parameters);
         if (WebRequestContext.IsPreview)
         {
             result = new MvcHtmlString(TridionMarkup.ParseEntity(result.ToString()));
         }
         return result;
     }
     return null;
 }
开发者ID:MrSnowflake,项目名称:tri,代码行数:40,代码来源:DD4TRenderer.cs

示例12: PagerBuilder

 internal PagerBuilder(HtmlHelper html, AjaxHelper ajax, string actionName, string controllerName,
     int totalPageCount, int pageIndex, PagerOptions pagerOptions, string routeName, RouteValueDictionary routeValues,
     MvcAjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes)
 {
     _ajaxPagingEnabled = (ajax != null);
     if (pagerOptions == null)
         pagerOptions = new PagerOptions();
     _html = html;
     _ajax = ajax;
     _actionName = actionName;
     _controllerName = controllerName;
     if (pagerOptions.MaxPageIndex == 0 || pagerOptions.MaxPageIndex > totalPageCount)
         _totalPageCount = totalPageCount;
     else
         _totalPageCount = pagerOptions.MaxPageIndex;
     _pageIndex = pageIndex;
     _pagerOptions = pagerOptions;
     _routeName = routeName;
     _routeValues = routeValues;
     _ajaxOptions = ajaxOptions;
     _htmlAttributes = htmlAttributes;
     // start page index
     _startPageIndex = pageIndex - (pagerOptions.NumericPagerItemCount / 2);
     if (_startPageIndex + pagerOptions.NumericPagerItemCount > _totalPageCount)
         _startPageIndex = _totalPageCount + 1 - pagerOptions.NumericPagerItemCount;
     if (_startPageIndex < 1)
         _startPageIndex = 1;
     // end page index
     _endPageIndex = _startPageIndex + _pagerOptions.NumericPagerItemCount - 1;
     if (_endPageIndex > _totalPageCount)
         _endPageIndex = _totalPageCount;
 }
开发者ID:jasonoiu,项目名称:OIU.CorporateWebsite,代码行数:32,代码来源:PagerBuilder.cs

示例13: Pager

        public Pager(HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary, string labelPrevious, string labelNext)
            : this()
        {
            this._htmlHelper = htmlHelper;
            this.pageSize = pageSize;
            this.currentPage = currentPage;
            this.totalItemCount = totalItemCount;
            this.linkWithoutPageValuesDictionary = valuesDictionary;
            var queryString = htmlHelper.ViewContext.RequestContext.HttpContext.Request.QueryString;
            //if (queryString.Count > 0)
            //{
            //    //Add querystring into routevalues.
            //    foreach (var key in queryString.Keys)
            //    {
            //        if (!valuesDictionary.ContainsKey(key))
            //        {
            //            valuesDictionary.Add(key, queryString[key]);
            //        }
            //    }
            //}

            if (labelPrevious != null)
            {
                this.LabelPrevious = labelPrevious;
            }
            if (labelNext != null)
            {
                this.LabelNext = labelNext;
            }
        }
开发者ID:jorgebay,项目名称:nearforums,代码行数:30,代码来源:PagerExtensions.cs

示例14: BuildContent

        public static string BuildContent(HtmlHelper html, string Content)
        {
            var matches = Regex.Matches(Content, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase);
            foreach (Match match in matches)
            {
                string url = match.Groups[1].Value;
                if (!url.Contains("cid"))
                {

                    string imagetagstr = Postal.HtmlExtensions.EmbedImage(html, url, "").ToHtmlString();
                    string newcid = Regex.Match(imagetagstr, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;
                    Content = Content.Replace(url, newcid);
                }
            }

            matches = Regex.Matches(Content, @"background:url\('(?<bgpath>.*)'\)", RegexOptions.IgnoreCase);
            foreach (Match match in matches)
            {
                string url = match.Groups[1].Value;
                if (!url.Contains("cid"))
                {
                    string imagetagstr = Postal.HtmlExtensions.EmbedImage(html, url, "").ToHtmlString();
                    string newcid = Regex.Match(imagetagstr, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;

                    Content = Content.Replace(url, newcid);
                }
            }
            return Content;
        }
开发者ID:dinhha,项目名称:TheDeck,代码行数:29,代码来源:GuMail.cs

示例15: FrontHtmlHelper

 public FrontHtmlHelper(Page_Context context, HtmlHelper html, ViewRender viewRender, ProxyRender proxyRender)
 {
     this.PageContext = context;
     this.Html = html;
     this.ViewRender = viewRender;
     this.ProxyRender = proxyRender;
 }
开发者ID:jason1234,项目名称:CMS,代码行数:7,代码来源:FrontHtmlHelper.cs


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