本文整理汇总了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) + "...";
}
示例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;
}
示例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);
}
示例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());
}
}
示例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));
}
示例6: BuildButton
/// <summary>
/// Creates the HTML for a submit <button>.
/// </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));
}
示例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);
}
示例8: AddModelError
public static void AddModelError(this ModelStateDictionary dictionary, string key, IHtmlString errorMessage)
{
dictionary.AddModelError(key, errorMessage.ToHtmlString());
}
示例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"
}
示例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"
}
示例11: ToIframeHtml
protected HtmlNode ToIframeHtml(IHtmlString html)
{
var doc = new HtmlDocument();
doc.LoadHtml(html.ToHtmlString());
return doc.DocumentNode.SelectSingleNode("//iframe");
}
示例12: Write
public void Write(IHtmlString htmlString)
{
Write(htmlString.ToHtmlString());
}
示例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;
}
示例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));
}
示例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
//.........这里部分代码省略.........