本文整理汇总了C#中TagBuilder类的典型用法代码示例。如果您正苦于以下问题:C# TagBuilder类的具体用法?C# TagBuilder怎么用?C# TagBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TagBuilder类属于命名空间,在下文中一共展示了TagBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImageActionLink
public static MvcHtmlString ImageActionLink(
this HtmlHelper helper,
string imageUrl,
string altText,
string actionName,
string controllerName,
object routeValues,
object linkHtmlAttributes,
object imgHtmlAttributes)
{
var linkAttributes = AnonymousObjectToKeyValue(linkHtmlAttributes);
var imgAttributes = AnonymousObjectToKeyValue(imgHtmlAttributes);
var imgBuilder = new TagBuilder("img");
imgBuilder.MergeAttribute("src", imageUrl);
imgBuilder.MergeAttribute("alt", altText);
imgBuilder.MergeAttributes(imgAttributes, true);
var urlHelper = new UrlHelper(helper.ViewContext.RequestContext, helper.RouteCollection);
var linkBuilder = new TagBuilder("a");
linkBuilder.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routeValues));
linkBuilder.MergeAttributes(linkAttributes, true);
var text = linkBuilder.ToString(TagRenderMode.StartTag);
text += imgBuilder.ToString(TagRenderMode.SelfClosing);
text += linkBuilder.ToString(TagRenderMode.EndTag);
return MvcHtmlString.Create(text);
}
示例2: BuildWidget
private static string BuildWidget()
{
var widget = new TagBuilder("div");
widget.MergeAttribute("class", "g-recaptcha");
widget.MergeAttribute("data-sitekey", ReCaptchaConfiguration.Instance.SiteKey);
return widget.ToString(TagRenderMode.Normal);
}
示例3: Foo
public static HtmlString Foo(this HtmlHelper h, string attr, string id, string tagElement)
{
var tBuilder = new TagBuilder(tagElement);
tBuilder.GenerateId(attr + id);
var c = new HtmlString(tBuilder.ToString());
return c;
}
示例4: TestTagBuilder
/// <summary>
/// Function to render the HTML block for the update/cancel buttons for a details edit form
/// </summary>
/// <param name="helper">Reference to the HTML helper class</param>
/// <returns>HTML string for the buttons block</returns>
public static HtmlString TestTagBuilder()
{
// Create the tags we need
var div = new TagBuilder("div");
var update = new TagBuilder("a");
var cancel = new TagBuilder("a");
// Center the div tag
div.AddCssClass("details-update-button-set");
// Set up the update submit button
update.Attributes.Add("id", "save-button");
update.Attributes.Add("tabindex", "0");
update.AddCssClass("snap-button k-button k-button-icontext");
update.SetInnerText("Update");
// Set up the cancel button
cancel.Attributes.Add("id", "cancel-button");
cancel.Attributes.Add("tabindex", "0");
cancel.AddCssClass("snap-button k-button k-button-icontext");
cancel.SetInnerText("Cancel");
// Set the HTML for the div and return it
div.InnerHtml = update.ToString() + cancel.ToString();
return new HtmlString(div.ToString());
}
示例5: Write
internal static void Write(HierarchyNode<ContentItem> hierarchy, ContentItem selectedItem, IContentAdapterProvider adapters, ItemFilter filter, string selectableTypes, string selectableExtensions, bool excludeRoot, string target, TextWriter writer)
{
N2.Web.Tree.Using(hierarchy)
.OpenTo(selectedItem)
.Filters(filter)
.IdProvider(n => "u" + n.Current.ID, n => "l" + n.Current.ID)
.LinkWriter((n, w) =>
{
BuildLink(adapters.ResolveAdapter<NodeAdapter>(n.Current), n.Current, n.Current.Path == selectedItem.Path, target, IsSelectable(n.Current, selectableTypes, selectableExtensions)).WriteTo(w);
if (n.Children.Count == 0 && adapters.ResolveAdapter<NodeAdapter>(n.Current).HasChildren(n.Current, filter))
{
var ul = new TagBuilder("ul");
ul.AddCssClass("ajax");
w.Write(ul.ToString(TagRenderMode.StartTag));
var li = new TagBuilder("li");
li.InnerHtml = "{url:" + Url.ParseTokenized("{ManagementUrl}/Content/Navigation/LoadTree.ashx")
.AppendQuery("target", target)
.AppendQuery(SelectionUtility.SelectedQueryKey, HttpUtility.UrlEncode(n.Current.Path))
.AppendQuery("selectableTypes", selectableTypes)
.AppendQuery("selectableExtensions", selectableExtensions)
+ "}";
w.Write(li.ToString());
w.Write(ul.ToString(TagRenderMode.EndTag));
}
})
.ExcludeRoot(excludeRoot)
.WriteTo(writer);
}
示例6: Script
/// <summary>
/// Loads a script int the view
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="configKey">configuration key value, configured in appsettings</param>
/// <returns></returns>
/// <exception cref="System.Exception"></exception>
public static MvcHtmlString Script(this HtmlHelper htmlHelper, string filePath)
{
if (UseContentDeliveryNetwork)
filePath = filePath.Replace("~", ContentUrlPrefix);
if (string.Compare(WorkEnvironment, "Development", StringComparison.CurrentCultureIgnoreCase) == 0)
{
var filePathWithoutMin = filePath.Replace(".min", string.Empty);
if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(filePathWithoutMin)))
{
filePath = filePathWithoutMin;
}
}
if (string.IsNullOrEmpty(filePath))
{
throw new Exception(string.Format("Mvc3.ContentManagement: Resource not found for {0}", filePath));
}
else
{
TagBuilder tagBuilder = new TagBuilder("script");
tagBuilder.MergeAttribute("src", UrlHelper.GenerateContentUrl(filePath, htmlHelper.ViewContext.HttpContext));
tagBuilder.MergeAttribute("type", "text/javascript");
return new MvcHtmlString(tagBuilder.ToString());
}
}
示例7: InputHelper
public static MvcHtmlString InputHelper(InputTypeHelper inputType,string name, string value, string innerScript,string classAttr, object htmlAttributes)
{
StringBuilder strBuilder = new StringBuilder();
TagBuilder tagScript = new TagBuilder("script");
tagScript.InnerHtml = "$(document).ready(function () {";
tagScript.InnerHtml += innerScript;
tagScript.InnerHtml += "});";
strBuilder.Append(tagScript.ToString());
TagBuilder tagInput = new TagBuilder("input");
if (htmlAttributes != null)
tagInput.MergeAttributes<string, object>(((IDictionary<string, object>)new RouteValueDictionary(htmlAttributes)));
tagInput.MergeAttribute("type",inputType.ToString());
tagInput.MergeAttribute("name", name);
tagInput.MergeAttribute("id", name);
tagInput.MergeAttribute("class", classAttr);
if(inputType==InputTypeHelper.button)
tagInput.MergeAttribute("title", value);
else
tagInput.MergeAttribute("value", value);
strBuilder.Append(tagInput.ToString(TagRenderMode.SelfClosing));
return MvcHtmlString.Create(strBuilder.ToString());
}
示例8: BeginAlertHelper
private static BootstrapAlert BeginAlertHelper(this HtmlHelper html, string alertClassName, string title, string id, string className)
{
TagBuilder tag = new TagBuilder("div");
tag.AddOrMergeAttribute("class", "alert");
if (!String.IsNullOrEmpty(alertClassName))
tag.AddOrMergeAttribute("class", alertClassName);
if (!String.IsNullOrEmpty(className))
tag.AddOrMergeAttribute("class", className);
if (!String.IsNullOrEmpty(id))
tag.Attributes.Add("id", id);
html.ViewContext.Writer.Write(tag.ToString(TagRenderMode.StartTag));
if (!String.IsNullOrEmpty(title))
{
TagBuilder titleTag = new TagBuilder("h4");
titleTag.MergeAttribute("class", "alert-heading");
titleTag.SetInnerText(title);
html.ViewContext.Writer.Write(titleTag.ToString(TagRenderMode.Normal));
}
BootstrapAlert theAlert = new BootstrapAlert(html.ViewContext);
return theAlert;
}
示例9: ContentZone
public IHtmlContent ContentZone(dynamic Display, dynamic Shape)
{
var htmlContents = new List<IHtmlContent>();
var shapes = ((IEnumerable<dynamic>)Shape);
var tabbed = shapes.GroupBy(x => (string)x.Metadata.Tab);
if (tabbed.Count() > 1)
{
foreach (var tab in tabbed)
{
var tabName = String.IsNullOrWhiteSpace(tab.Key) ? "Content" : tab.Key;
var tabBuilder = new TagBuilder("div");
tabBuilder.Attributes["id"] = "tab-" + tabName.HtmlClassify();
tabBuilder.Attributes["data-tab"] = tabName;
foreach (var item in tab)
{
tabBuilder.InnerHtml.AppendHtml(Display(item));
}
htmlContents.Add(tabBuilder);
}
}
else
{
foreach (var item in tabbed.First())
{
htmlContents.Add(Display(item));
}
}
// TODO: Replace by HtmlContentBuilder when available
var combined = new DisplayHelper.Combined(htmlContents);
return combined;
}
示例10: ClearDiv
public static string ClearDiv()
{
var myClearDiv = new TagBuilder("div");
myClearDiv.MergeAttribute("class", "clear");
myClearDiv.InnerHtml = " ";
return myClearDiv.ToString();
}
示例11: PageLinks
public static MvcHtmlString PageLinks(
this HtmlHelper html,
PagingInfo info,
Func<int, string> url
)
{
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= info.TotalPages; i++)
{
TagBuilder tag = null;
if (i == info.CurrentPage)
{
tag = new TagBuilder("span");
tag.AddCssClass("selected");
}
else
{
tag = new TagBuilder("a");
tag.MergeAttribute("href", url(i));
}
tag.InnerHtml = i.ToString(CultureInfo.InvariantCulture);
sb.Append(tag.ToString());
}
return MvcHtmlString.Create(sb.ToString());
}
示例12: CheckBoxList
public static MvcHtmlString CheckBoxList(this HtmlHelper htmlHelper, string name, MultiSelectList listInfo, IDictionary<string, object> htmlAttributes)
{
if (String.IsNullOrEmpty(name))
throw new ArgumentException("The argument must have a value", "name");
if (listInfo == null)
throw new ArgumentNullException("listInfo");
if (listInfo.Count() < 1)
throw new ArgumentException("The list must contain at least one value", "listInfo");
StringBuilder sb = new StringBuilder();
foreach (SelectListItem info in listInfo)
{
TagBuilder builder = new TagBuilder("input");
if (info.Selected) builder.MergeAttribute("checked", "checked");
builder.MergeAttributes<string, object>(htmlAttributes);
builder.MergeAttribute("type", "checkbox");
builder.MergeAttribute("value", info.Value);
builder.MergeAttribute("name", name);
builder.InnerHtml = info.Text;
sb.Append(builder.ToString(TagRenderMode.Normal));
sb.Append("<br />");
}
return MvcHtmlString.Create(sb.ToString());
}
示例13: PagedListGoToPageForm
///<summary>
/// Displays a configurable "Go To Page:" form for instances of PagedList.
///</summary>
///<param name="html">This method is meant to hook off HtmlHelper as an extension method.</param>
///<param name="list">The PagedList to use as the data source.</param>
///<param name="formAction">The URL this form should submit the GET request to.</param>
///<param name="options">Formatting options.</param>
///<returns>Outputs the "Go To Page:" form HTML.</returns>
public static MvcHtmlString PagedListGoToPageForm(this System.Web.Mvc.HtmlHelper html,
IPagedList list,
string formAction,
GoToFormRenderOptions options)
{
var form = new TagBuilder("form");
form.AddCssClass("PagedList-goToPage");
form.Attributes.Add("action", formAction);
form.Attributes.Add("method", "get");
var fieldset = new TagBuilder("fieldset");
var label = new TagBuilder("label");
label.Attributes.Add("for", options.InputFieldName);
label.SetInnerText(options.LabelFormat);
var input = new TagBuilder("input");
input.Attributes.Add("type", options.InputFieldType);
input.Attributes.Add("name", options.InputFieldName);
input.Attributes.Add("value", list.PageNumber.ToString());
var submit = new TagBuilder("input");
submit.Attributes.Add("type", "submit");
submit.Attributes.Add("value", options.SubmitButtonFormat);
fieldset.InnerHtml = label.ToString();
fieldset.InnerHtml += input.ToString(TagRenderMode.SelfClosing);
fieldset.InnerHtml += submit.ToString(TagRenderMode.SelfClosing);
form.InnerHtml = fieldset.ToString();
return new MvcHtmlString(form.ToString());
}
示例14: GetGoogleMapCanvas
/// <summary>
/// Get Google Maps Canvas Tag
/// </summary>
/// <returns></returns>
private static string GetGoogleMapCanvas()
{
var canvasBuilder = new TagBuilder("div");
canvasBuilder.MergeAttribute("id", "map_canvas");
canvasBuilder.MergeAttribute("style", @"height: 500px");
return "\n" + canvasBuilder.ToString();
}
示例15: Css
public static MvcHtmlString Css(this HtmlHelper helper, string file, string mediaType)
{
if (String.IsNullOrEmpty(file))
{
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "file");
}
string src;
if (ScriptExtensions.IsRelativeToDefaultPath(file))
{
src = "~/Content/" + file;
}
else
{
src = file;
}
TagBuilder linkTag = new TagBuilder("link");
linkTag.MergeAttribute("type", "text/css");
linkTag.MergeAttribute("rel", "stylesheet");
if (mediaType != null)
{
linkTag.MergeAttribute("media", mediaType);
}
linkTag.MergeAttribute("href", UrlHelper.GenerateContentUrl(src, helper.ViewContext.HttpContext));
return MvcHtmlString.Create(linkTag.ToString(TagRenderMode.SelfClosing));
}