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


C# IHtmlString.ToHtmlString方法代码示例

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


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

示例1: Truncate

 public static object Truncate(IHtmlString htmlString, int length)
 {
     if (htmlString.ToHtmlString().Length <= length)
     {
         return htmlString.ToHtmlString();
     }
     return htmlString.ToHtmlString().Substring(0, length) + "...";
 }
开发者ID:fitba,项目名称:km-2013-projects-team-majevica,代码行数:8,代码来源:HtmlHelpers.cs

示例2: HasTag

 protected bool HasTag(IHtmlString html, string tag)
 {
     var doc = new HtmlDocument();
     doc.LoadHtml(html.ToHtmlString());
     var xpath = "//" + tag;
     return doc.DocumentNode.SelectSingleNode(xpath) != null;
 }
开发者ID:jv9,项目名称:MvcReportViewer,代码行数:7,代码来源:IframeTests.cs

示例3: InsertAttributes

    /// <summary>
    /// Inserts the given attributes at the end of all opening tags in this HtmlString.
    /// </summary>
    /// <param name="htmlString">The HTML string.</param>
    /// <param name="attributeValues">The attribute values.</param>
    /// <exception cref="System.NullReferenceException"></exception>
    /// <exception cref="System.ArgumentException">No opening tag in IHtmlString: {0} + html;htmlString</exception>
    private static IHtmlString InsertAttributes(IHtmlString htmlString, IEnumerable<Tuple<string, object>> attributeValues)
    {
        if (htmlString == null) throw new NullReferenceException();

        var attributes = new StringBuilder();
        foreach (var t in attributeValues)
        {
            attributes.AppendFormat(" {0}=\"{1}\"",
                HttpUtility.HtmlEncode(t.Item1).ToLower(),
                HttpUtility.HtmlEncode((t.Item2 ?? String.Empty).ToString()));
        }

        var html = htmlString.ToHtmlString();

        var matches = GetOpeningTagMatches(html);
        if (matches.Count == 0)
            throw new ArgumentException("No opening tag in IHtmlString: {0}" + html, "htmlString");

        foreach (Match match in matches)
        {
            var endOfOpeningTag = match.Groups[3].Index;
            html = html.Insert(endOfOpeningTag, attributes.ToString());
        }

        return new HtmlString(html);
    }
开发者ID:raziqyork,项目名称:UsefulCode,代码行数:33,代码来源:HtmlStringExtensions.cs

示例4: FlowFormMessage

        public FlowFormMessage(TextWriter writer, MessageType messageType, string heading, IHtmlString message = null)
        {
            _writer = writer;
            _writer.Write(HelperDefinitions.BeginMessage(messageType.ToDescription(), heading).ToHtmlString());

            if (message != null)
            {
                _writer.Write(message.ToHtmlString());
                _writer.Write(HelperDefinitions.EndMessage().ToHtmlString());
            }
        }
开发者ID:SharePointSusan,项目名称:Research-Data-Manager,代码行数:11,代码来源:FlowFormMessage.cs

示例5: Render

        private static HtmlString Render(IHtmlString html, string replaceTemplate)
        {
            var scriptsAsString = html.ToHtmlString();
            var bundleEntries = scriptsAsString.Split(new string[] { Environment.NewLine.ToString() },
                StringSplitOptions.RemoveEmptyEntries);

            string src = string.Format(replaceTemplate, string.Empty);

            string version = Assembly.GetExecutingAssembly().GetFormatedVersion("/v{0}_{1}_{2}_{3}");
            string markerWithVersion = string.Format(replaceTemplate, version);

            bundleEntries = bundleEntries.Select(x => { return x.Replace(src, markerWithVersion); }).ToArray();

            return new HtmlString(string.Join(Environment.NewLine, bundleEntries));
        }
开发者ID:roelvanlisdonk,项目名称:Research,代码行数:15,代码来源:Bundle.cs

示例6: BuildButton

        /// <summary>
        /// Creates the HTML for a submit &lt;button&gt;.
        /// </summary>
        /// <param name="content">The content to display for the button</param>
        /// <param name="type">The type of submit button; submit (default) or reset</param>
        /// <param name="value">The value to submit with the button</param>
        /// <param name="id">The id/name to use for the button</param>
        /// <param name="htmlAttributes">Any HTML attributes that should be applied to the button</param>
        /// <returns>The HTML for the submit button</returns>
        public static IHtmlString BuildButton(IHtmlString content, string type = null, string id = null, string value = null, HtmlAttributes htmlAttributes = null)
        {
            var t = new TagBuilder("button") {InnerHtml = content.ToHtmlString()};
            if (value != null)
                t.Attributes.Add("value", value);
            if (type != null)
                t.Attributes.Add("type", type);
            if (id != null)
            {
                t.Attributes.Add("id", id);
                t.Attributes.Add("name", id);
            }
            if (htmlAttributes != null)
                t.MergeAttributes(htmlAttributes.Attributes, true);

            return new HtmlString(t.ToString(TagRenderMode.Normal));
        }
开发者ID:Royce,项目名称:ChameleonForms,代码行数:26,代码来源:HtmlCreator.cs

示例7: BeginConditionalLink

        /// <summary>
        /// Writes an opening <![CDATA[ <a> ]]> tag to the response if the shouldWriteLink argument is true.
        /// Returns a ConditionalLink object which when disposed will write a closing <![CDATA[ </a> ]]> tag
        /// to the response if the shouldWriteLink argument is true.
        /// </summary>
        public static ConditionalLink BeginConditionalLink(this HtmlHelper helper, bool shouldWriteLink, IHtmlString url, string title = null, string cssClass = null)
        {
            if(shouldWriteLink)
            {
                var linkTag = new TagBuilder("a");
                linkTag.Attributes.Add("href", url.ToHtmlString());

                if(!string.IsNullOrWhiteSpace(title))
                {
                    linkTag.Attributes.Add("title", helper.Encode(title));
                }

                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    linkTag.Attributes.Add("class", cssClass);
                }

                helper.ViewContext.Writer.Write(linkTag.ToString(TagRenderMode.StartTag));
            }
            return new ConditionalLink(helper.ViewContext, shouldWriteLink);
        }
开发者ID:valdisiljuconoks,项目名称:EPiBootstrapArea,代码行数:26,代码来源:HtmlHelpers.cs

示例8: AddModelError

 public static void AddModelError(this ModelStateDictionary dictionary, string key, IHtmlString errorMessage)
 {
     dictionary.AddModelError(key, errorMessage.ToHtmlString());
 }
开发者ID:moretti,项目名称:i18n,代码行数:4,代码来源:I18NController.cs

示例9: BeginFieldInternal

public static System.Web.WebPages.HelperResult BeginFieldInternal(IHtmlString labelHtml, IHtmlString elementHtml, IHtmlString validationHtml, IReadonlyFieldConfiguration fieldConfiguration, ModelMetadata fieldMetadata, IHtmlString requiredDesignator) {
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {

#line 62 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                                                                                                                                                                     


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "            <dt>");


#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, labelHtml);


#line default
#line hidden

#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, new HtmlString(fieldMetadata != null && fieldMetadata.IsRequired ? requiredDesignator.ToHtmlString() : ""));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "</dt>\r\n");

WriteLiteralTo(__razor_helper_writer, "            <dd>\r\n");

WriteLiteralTo(__razor_helper_writer, "                ");


#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, GetPrependedHtml(fieldConfiguration));


#line default
#line hidden

#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                         WriteTo(__razor_helper_writer, elementHtml);


#line default
#line hidden

#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                     WriteTo(__razor_helper_writer, GetAppendedHtml(fieldConfiguration));


#line default
#line hidden

#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                         WriteTo(__razor_helper_writer, GetHint(fieldConfiguration));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, " ");


#line 65 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                                                      WriteTo(__razor_helper_writer, validationHtml);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\r\n");


#line 66 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"


#line default
#line hidden
});

#line 66 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
}
开发者ID:TravisTheTechie,项目名称:ChameleonForms,代码行数:82,代码来源:DefaultHtmlHelpers.generated.cs

示例10: BeginMessage

public static System.Web.WebPages.HelperResult BeginMessage(MessageType messageType, IHtmlString heading) {
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {

#line 95 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                    


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "      <div class=\"");


#line 96 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, string.Format("{0}{1}", messageType.ToString().ToLower(), "_message"));


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\">\r\n");


#line 97 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
            if (!string.IsNullOrEmpty(heading.ToHtmlString()))
            {


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "          <h3>");


#line 99 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, heading);


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "</h3>\r\n");


#line 100 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
            }


#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "          <div class=\"message\">\r\n");


#line 102 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"


#line default
#line hidden
});

#line 102 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
}
开发者ID:TravisTheTechie,项目名称:ChameleonForms,代码行数:60,代码来源:DefaultHtmlHelpers.generated.cs

示例11: ToIframeHtml

 protected HtmlNode ToIframeHtml(IHtmlString html)
 {
     var doc = new HtmlDocument();
     doc.LoadHtml(html.ToHtmlString());
     return doc.DocumentNode.SelectSingleNode("//iframe");
 }
开发者ID:jv9,项目名称:MvcReportViewer,代码行数:6,代码来源:IframeTests.cs

示例12: Write

 public void Write(IHtmlString htmlString)
 {
     Write(htmlString.ToHtmlString());
 }
开发者ID:FerozAhmed,项目名称:bootstrapcomponents,代码行数:4,代码来源:StringBuilderWriter.cs

示例13: ExtractScriptTags

 private IList<XElement> ExtractScriptTags(IHtmlString html)
 {
     // To help us inspect the HTML, we will parse as XML.
     var root = XDocument.Parse("<root>" + html.ToHtmlString() + "</root>").Root;
     var scripts = root.Elements().ToList();
     return scripts;
 }
开发者ID:apoco,项目名称:jacobsoft,代码行数:7,代码来源:HtmlHelperExtensionsTests.cs

示例14: BuildLabel

        /// <summary>
        /// Creates the HTML for a label.
        /// </summary>
        /// <param name="for">The name/id for the checkbox</param>
        /// <param name="labelText">The text inside the label</param>
        /// <param name="htmlAttributes">Any HTML attributes that should be applied to the checkbox</param>
        /// <returns>The HTML for the checkbox</returns>
        public static IHtmlString BuildLabel(string @for, IHtmlString labelText, HtmlAttributes htmlAttributes)
        {
            var t = new TagBuilder("label");
            t.Attributes.Add("for", TagBuilder.CreateSanitizedId(@for));
            t.InnerHtml = labelText.ToHtmlString();

            if (htmlAttributes != null)
                t.MergeAttributes(htmlAttributes.Attributes, false);

            return new HtmlString(t.ToString(TagRenderMode.Normal));
        }
开发者ID:Royce,项目名称:ChameleonForms,代码行数:18,代码来源:HtmlCreator.cs

示例15: BeginFieldInternal

public static System.Web.WebPages.HelperResult BeginFieldInternal(IHtmlString labelHtml, IHtmlString elementHtml, IHtmlString validationHtml, IReadonlyFieldConfiguration fieldConfiguration, ModelMetadata fieldMetadata, IHtmlString requiredDesignator) {
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {



#line 61 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                                                                                                                                                                     

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "            <dt>");



#line 62 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WebViewPage.WriteTo(@__razor_helper_writer, labelHtml);

#line default
#line hidden



#line 62 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WebViewPage.WriteTo(@__razor_helper_writer, new HtmlString(fieldMetadata != null && fieldMetadata.IsRequired ? requiredDesignator.ToHtmlString() : ""));

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</dt>\r\n");



WebViewPage.WriteLiteralTo(@__razor_helper_writer, "            <dd");



#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WebViewPage.WriteTo(@__razor_helper_writer, RenderIfNotEmpty(fieldConfiguration.FieldContainerClasses,item => new System.Web.WebPages.HelperResult(__razor_template_writer => {

#line default
#line hidden


WebViewPage.WriteLiteralTo(@__razor_template_writer, " class=\"");



#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                               WebViewPage.WriteTo(@__razor_template_writer, fieldConfiguration.FieldContainerClasses);

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_template_writer, "\"");



#line 63 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                                                                                                           })));

#line default
#line hidden

WebViewPage.WriteLiteralTo(@__razor_helper_writer, ">\r\n");



WebViewPage.WriteLiteralTo(@__razor_helper_writer, "                ");



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
WebViewPage.WriteTo(@__razor_helper_writer, GetPrependedHtml(fieldConfiguration));

#line default
#line hidden



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
            WebViewPage.WriteTo(@__razor_helper_writer, elementHtml);

#line default
#line hidden



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                        WebViewPage.WriteTo(@__razor_helper_writer, GetAppendedHtml(fieldConfiguration));

#line default
#line hidden



#line 64 "..\..\Templates\Default\DefaultHtmlHelpers.cshtml"
                                                            WebViewPage.WriteTo(@__razor_helper_writer, GetHint(fieldConfiguration));

#line default
//.........这里部分代码省略.........
开发者ID:Javaman2,项目名称:ChameleonForms,代码行数:101,代码来源:DefaultHtmlHelpers.generated.cs


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