本文整理汇总了C#中IHtmlString类的典型用法代码示例。如果您正苦于以下问题:C# IHtmlString类的具体用法?C# IHtmlString怎么用?C# IHtmlString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IHtmlString类属于命名空间,在下文中一共展示了IHtmlString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CacheRenderedTag
internal static void CacheRenderedTag(string virtualPath, IHtmlString renderedTag)
{
RenderedTags[virtualPath] = renderedTag;
var ctx = HttpContext.Current;
var physicalPath = ctx.Server.MapPath(virtualPath);
if (File.Exists(physicalPath))
{
// add file watcher
var fsw = new FileSystemWatcher(
Path.GetDirectoryName(physicalPath), Path.GetFileName(physicalPath));
FileSystemWatchers.Add(fsw);
// remove from lookup on change, to allow for creation of new md5 hash
fsw.Renamed += (sender, args) =>
{
RenderedTags.Remove(virtualPath);
};
fsw.Changed += (sender, args) =>
{
RenderedTags.Remove(virtualPath);
};
fsw.Deleted += (sender, args) =>
{
RenderedTags.Remove(virtualPath);
};
fsw.Created += (sender, args) =>
{
RenderedTags.Remove(virtualPath);
};
fsw.EnableRaisingEvents = true;
}
}
示例2: 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);
}
示例3: 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;
}
示例4: Concact
public static IHtmlString Concact(this IHtmlString html, IHtmlString other)
{
StringBuilder sb = new StringBuilder();
sb.Append(html.ToString());
sb.Append(other.ToString());
return new HtmlString(sb.ToString());
}
示例5: FlowFormField
public FlowFormField(TextWriter writer, bool containsSection, string labelHtml, string elementHtml, string errorHtml = "", bool isValid = true, IHtmlString hint = null, string tip = null, bool hideTip = true, string hintClass = null, string parentClass = null, bool displayFieldName = true)
{
_containsSection = containsSection;
_writer = writer;
var generatedSection = HelperDefinitions.BeginField(containsSection, displayFieldName ? new HtmlString(labelHtml) : null, new HtmlString(elementHtml), new HtmlString(errorHtml), isValid, hint, tip, hideTip, hintClass, parentClass);
_writer.Write(generatedSection.ToHtmlString());
}
示例6: Truncate
public static object Truncate(IHtmlString htmlString, int length)
{
if (htmlString.ToHtmlString().Length <= length)
{
return htmlString.ToHtmlString();
}
return htmlString.ToHtmlString().Substring(0, length) + "...";
}
示例7: LabelAndControl
public LabelAndControl(ViewContext viewContext, string labelFor, string labelText, IHtmlString control)
{
_labelFor = labelFor;
_labelText = labelText;
_control = control;
_formLayout = viewContext.TempData["BootstrapFormLayout"].ToString();
HtmlAttributes["class"] = "control-group";
}
示例8: CreateField
public static IHtmlString CreateField(this HtmlHelper html, string title, IHtmlString input, IHtmlString validation = null)
{
var result = string.Format(@"<div class=""control-group""><label for=""control-label"">{0}</label><div class=""controls"">{1}</div></div>", title, input);
if (validation != null) {
result = string.Format(@"<div class=""control-group""><label for=""control-label"">{0}</label><div class=""controls"">{1}<p>{2}</p></div></div>", title, input, validation);
}
return new HtmlString(result);
}
示例9: BeginSection
public static System.Web.WebPages.HelperResult BeginSection(IHtmlString title, IHtmlString leadingHtml, HtmlAttributes htmlAttributes) {
#line default
#line hidden
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {
#line 14 "..\..\Templates\HtmlHelpers.cshtml"
#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, " <fieldset");
#line 15 "..\..\Templates\HtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, htmlAttributes);
#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, ">\r\n");
WriteLiteralTo(__razor_helper_writer, " <legend>");
#line 16 "..\..\Templates\HtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, title);
#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "</legend>\r\n");
WriteLiteralTo(__razor_helper_writer, " ");
#line 17 "..\..\Templates\HtmlHelpers.cshtml"
WriteTo(__razor_helper_writer, leadingHtml);
#line default
#line hidden
WriteLiteralTo(__razor_helper_writer, "\r\n");
WriteLiteralTo(__razor_helper_writer, " <dl>\r\n");
#line 19 "..\..\Templates\HtmlHelpers.cshtml"
#line default
#line hidden
});
#line 19 "..\..\Templates\HtmlHelpers.cshtml"
}
示例10: ActionLink
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper,
IHtmlString linkText,
string actionName,
string controllerName,
RouteValueDictionary routeValues,
IDictionary<string, Object> htmlAttributes)
{
var linkString = htmlHelper.ActionLink(guid, actionName, controllerName, routeValues, htmlAttributes);
return ReplaceGuidWithRealText(linkText.ToString(), linkString);
}
示例11: RenderSection
public HelperResult RenderSection(string name, IHtmlString defaultContents)
{
if (this.IsSectionDefined(name))
{
return this.RenderSection(name);
}
var result = new HelperResult((x) => x.Write(defaultContents.ToString()));
return this.RenderSection(name, (x) => result);
}
示例12: Create
/// <summary>
/// ����һ��MvcHtmlWrapper�������MvcHtmlWrapper��ֱ�ӷ��أ�
/// �������������������MvcHtmlWrapper��
/// </summary>
/// <param name="str">IHtmlString���ͣ�ʵ����ToHtmlString�ӿڵ�����</param>
/// <returns></returns>
public static MvcHtmlWrapper Create(IHtmlString str)
{
Contract.Requires(str != null);
if (str is MvcHtmlWrapper)
return str as MvcHtmlWrapper;
if (str is MvcHtmlString)
return new MvcHtmlWrapper(str);
Contract.Assert(false);
return null;
}
示例13: 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());
}
}
示例14: ConfigName
public void ConfigName(IHtmlString name) {
this.FieldNamePrefix = name.ToString();
if (String.IsNullOrEmpty(this.FieldNamePrefix)) {
this.FieldNamePrefix = String.Empty;
} else {
this.FieldNamePrefix = String.Format("{0}.", this.FieldNamePrefix);
}
this.FieldIdPrefix = this.FieldNamePrefix.Replace(".", "_").Replace("]", "_").Replace("[", "_");
}
示例15: DemoRow
public static IHtmlString DemoRow(this HtmlHelper htmlHelper, string title, IHtmlString body, string title2 = null, IHtmlString body2 = null)
{
bool hasSecondCol = !title2.IsNullOrWhiteSpace();
var colClass = hasSecondCol ? "col-sm-6" : "col-xs-12";
string rowFormat = @"<div class=""row demoRow"">
<div class=""{2} demoCol"">{0}</div>
<div class=""{2} demoCol"">{1}</div>
</div>";
return htmlHelper.Raw(string.Format(rowFormat, htmlHelper.DemoPanel(title, body), hasSecondCol ? htmlHelper.DemoPanel(title2, body2) : new HtmlString(""), colClass));
}