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


C# MvcHtmlString.ToHtmlString方法代码示例

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


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

示例1: WrapedInLabel

        public static HtmlString WrapedInLabel(this HtmlHelper helper, MvcHtmlString @object, object labelAttribtues = null, object wrappedObjectAttribtues = null)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder wrappedObjectSb = new StringBuilder();
            Match match = Regex.Match(@object.ToHtmlString(), @"id=""(?<ID>\w+)""");
            if (match.Success)
            {
                sb.AppendFormat("<label ");
                if (labelAttribtues != null)
                {
                    PropertyInfo[] propertyInfos = labelAttribtues.GetType().GetProperties();
                    foreach (PropertyInfo propertyInfo in propertyInfos)
                    {
                        sb.AppendFormat(@"{0}=""{1}"">", propertyInfo.Name, propertyInfo.GetValue(labelAttribtues, null));
                    }
                }
                sb.AppendFormat(@"<strong>{0}</strong>", match.Groups["ID"].Value);

                wrappedObjectSb.Append(@object.ToHtmlString());
                int firstWhiteSpace = @object.ToHtmlString().IndexOf(" ");

                if (wrappedObjectAttribtues != null)
                {
                    PropertyInfo[] propertyInfos = wrappedObjectAttribtues.GetType().GetProperties();
                    foreach (PropertyInfo propertyInfo in propertyInfos)
                    {
                        wrappedObjectSb.Insert(firstWhiteSpace,String.Format(@" {0}=""{1}"" ", propertyInfo.Name, propertyInfo.GetValue(wrappedObjectAttribtues, null)));
                    }
                }

                sb.AppendFormat("{0}", wrappedObjectSb);
                sb.Append("</label>");
            }
            return new HtmlString(sb.ToString());
        }
开发者ID:michal-franc,项目名称:ElearnServices,代码行数:35,代码来源:LabelWrap.cs

示例2: DefaultPagingHtml

        public static string DefaultPagingHtml(int option, MvcHtmlString actionLink = null, bool active = false)
        {
            switch (option)
            {
                case PagingOptConst.Wrapper: return @"<ul class=""pagination"">{0}{1}{2}{3}{4}</ul>";
                case PagingOptConst.FirstLastButton: return string.Format(@"<li class=""paging-first-last"">{0}</li>", actionLink.ToHtmlString());
                case PagingOptConst.PrevNextButton: return string.Format(@"<li class=""paging-prev-next"">{0}</li>", actionLink.ToHtmlString());
                case PagingOptConst.NumberButton: return string.Format(@"<li class=""page-number {0}"">{1}</li>", active ? "paging-active" : string.Empty, actionLink.ToHtmlString());
                case PagingOptConst.NoneActionString: return string.Format(@"<li class=""paging-none-action""><a href=""javascript:;"">...</a></li>");
            }

            return string.Empty;
        }
开发者ID:enclaveTeam,项目名称:Portal.eCommerces,代码行数:13,代码来源:CustomHtmlGenerator.cs

示例3: MenuItem

        public static MvcHtmlString MenuItem(this HtmlHelper helper, MvcHtmlString link, string controller)
        {
            var li = new TagBuilder("li");
            if (helper.ViewContext.Controller.GetType().Name.ToLower() == String.Format("{0}controller", controller).ToLower())
                li.Attributes.Add("class", "selected");
            li.InnerHtml = link.ToHtmlString();
            return new MvcHtmlString(li.ToString());
                

        }
开发者ID:juangdiaz,项目名称:NYU-CourseWork,代码行数:10,代码来源:HtmlHelpers.cs

示例4: resolve

        private static bool resolve(MvcHtmlString content, int characters, out string resolved)
        {
            var stripped = content == null ?
                        string.Empty : content.ToHtmlString().StripHtml();

            if (stripped.Length > characters)
            {
                resolved = stripped.FirstCharacters(characters);
                return true;
            }

            resolved = stripped;
            return false;
        }
开发者ID:Gutek,项目名称:MovingScrewdriver,代码行数:14,代码来源:DescriptionResolver.cs

示例5: HtmlHelperExtensionsImageAbsoultePathAndClassTest

        public void HtmlHelperExtensionsImageAbsoultePathAndClassTest()
        {
            // Przekazany url
            const string Url = "test.com/someimg.jpg";

            // Oczekiwany tag html
            var expected =
                new MvcHtmlString(
                    "<img alt=\"" + AlternateText + "\" class=\"" + Class + "\" id=\"" + Id + "\" src=\"" + Url
                    + "\" />");

            // stworzenie instancji HtmlHelper
            var htmlHelper = new HtmlHelper(new ViewContext(), Substitute.For<IViewDataContainer>());

            // Wykonanie helpera Image
            var tag = htmlHelper.Image(Id, Url, AlternateText, new { @class = Class });

            // Sprawdzenie
            Assert.IsInstanceOfType(tag, typeof(MvcHtmlString));
            Assert.AreEqual(expected.ToHtmlString(), tag.ToHtmlString());
        }
开发者ID:verenichvlad,项目名称:KNI,代码行数:21,代码来源:HtmlHelperExtensionsTests.cs

示例6: getIdFromString

        private static string getIdFromString(MvcHtmlString html)
        {
            string raw = html.ToHtmlString();
            if (raw.IndexOf("id=") == -1)
                throw new ArgumentException("MVC.Controls.DatePicker can only be used for MvcHtmlString with an html-id"
                    + Environment.NewLine + "[" + html.ToHtmlString() + "]");

            raw = raw.Substring(raw.IndexOf("id=") + 4);
            raw = raw.Substring(0, raw.IndexOf("\""));

            return raw;
        }
开发者ID:NH4CL,项目名称:UniProject,代码行数:12,代码来源:Manager.cs

示例7: ResponsiveTd

 public static MvcHtmlString ResponsiveTd(this HtmlHelper html, string label, MvcHtmlString content)
 {
     return new MvcHtmlString(string.Format(@"<td data-label=""{0}"">{1}</td>", label, content.ToHtmlString()));
 }
开发者ID:philwith,项目名称:racingresource,代码行数:4,代码来源:Extensions.cs

示例8: EmbeddedTemplate

 public static MvcHtmlString EmbeddedTemplate(EntityBase entityBase, MvcHtmlString template, string defaultString)
 {
     return MvcHtmlString.Create("<script type=\"template\" id=\"{0}\" data-toString=\"{2}\">{1}</script>".Formato(
                         entityBase.Compose(EntityBaseKeys.Template),
                         regex.Replace(template.ToHtmlString(), m => m.Value + "X"),
                         defaultString));
 }
开发者ID:nuub666,项目名称:framework,代码行数:7,代码来源:EntityBaseHelper.cs

示例9: AddLine

 public void AddLine(MvcHtmlString html)
 {
     if (!MvcHtmlString.IsNullOrEmpty(html))
         sb.AppendLine(html.ToHtmlString());
 }
开发者ID:nuub666,项目名称:framework,代码行数:5,代码来源:HtmlTag.cs

示例10: Concat

        public static MvcHtmlString Concat(this MvcHtmlString one, MvcHtmlString other)
        {
            if (MvcHtmlString.IsNullOrEmpty(one))
                return other;

            if (MvcHtmlString.IsNullOrEmpty(other))
                return one;

            return MvcHtmlString.Create(one.ToHtmlString() + other.ToHtmlString());
        }
开发者ID:nuub666,项目名称:framework,代码行数:10,代码来源:HtmlTag.cs

示例11: InnerHtml

        public HtmlTag InnerHtml(MvcHtmlString html)
        {
            if (MvcHtmlString.IsNullOrEmpty(html))
                tagBuilder.InnerHtml = null;
            else
                tagBuilder.InnerHtml = html.ToHtmlString();

            return this;
        }
开发者ID:nuub666,项目名称:framework,代码行数:9,代码来源:HtmlTag.cs

示例12: HtmlHelperExtensionsImageRelativePathTest

        public void HtmlHelperExtensionsImageRelativePathTest()
        {
            // Przekazany url
            const string Url = "~/someimg.jpg";

            // Oczekiwany url
            const string ExpectedUrl = "/app/someimg.jpg";

            // Oczekiwany tag html
            var expected =
                new MvcHtmlString("<img alt=\"" + AlternateText + "\" id=\"" + Id + "\" src=\"" + ExpectedUrl + "\" />");

            // stworzenie instancji HtmlHelper
            var htmlHelper = new HtmlHelper(new ViewContext(), Substitute.For<IViewDataContainer>());

            // Mokowanie HttpContextBase
            var fakeHttpContext = Substitute.ForPartsOf<HttpContextBase>();

            // Ustawienie właściwośći readonly Request
            // ReSharper disable once UnusedVariable
            fakeHttpContext.When(x => { var get = x.Request; }).DoNotCallBase();
            fakeHttpContext.Request.Returns(Substitute.ForPartsOf<HttpRequestBase>());

            // Ustawienie właściwośći readonly ApplicaitonPath
            // ReSharper disable once UnusedVariable
            fakeHttpContext.Request.When(x => { var get = x.ApplicationPath; }).DoNotCallBase();
            fakeHttpContext.Request.ApplicationPath.Returns("/app/");

            // Podststawienie i wykonanie helpera Image
            htmlHelper.ViewContext.HttpContext = fakeHttpContext;
            var tag = htmlHelper.Image(Id, Url, AlternateText);

            // Sprawdzenie
            Assert.IsInstanceOfType(tag, typeof(MvcHtmlString));
            Assert.AreEqual(expected.ToHtmlString(), tag.ToHtmlString());
        }
开发者ID:verenichvlad,项目名称:KNI,代码行数:36,代码来源:HtmlHelperExtensionsTests.cs

示例13: GrayButton

 public static MvcHtmlString GrayButton(this HtmlHelper html, MvcHtmlString content)
 {
     return GrayButton(html, content.ToHtmlString());
 }
开发者ID:jacklau88,项目名称:Forms,代码行数:4,代码来源:HtmlExtensions.cs

示例14: ReplaceNewLines

 public static MvcHtmlString ReplaceNewLines(this HtmlHelper htmlHelper, MvcHtmlString str)
 {
     string pattern = @"\r\n|\n\r|\r|\n";
     string  htmlStr = str.ToHtmlString();
     string result = Regex.Replace(htmlStr, pattern, " ");
     StringBuilder builder = new StringBuilder();
     builder.Append(result);
     return MvcHtmlString.Create(builder.ToString());
 }
开发者ID:zhouleink,项目名称:ChinaTea,代码行数:9,代码来源:HtmlExtensions.cs


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