本文整理汇总了C#中TagBuilder.ToMvcHtmlString方法的典型用法代码示例。如果您正苦于以下问题:C# TagBuilder.ToMvcHtmlString方法的具体用法?C# TagBuilder.ToMvcHtmlString怎么用?C# TagBuilder.ToMvcHtmlString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TagBuilder
的用法示例。
在下文中一共展示了TagBuilder.ToMvcHtmlString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CustomValidationSummary
public static MvcHtmlString CustomValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message, IDictionary<string, object> htmlAttributes)
{
MvcHtmlString originalValidation = ValidationExtensions.ValidationSummary(htmlHelper, excludePropertyErrors, message, htmlAttributes);
StringBuilder divAlertMessageErrorContainer = new StringBuilder();
TagBuilder divAlertMessageError = new TagBuilder("div");
divAlertMessageError.AddCssClass("validation-summary-valid");
divAlertMessageError.AddCssClass("alert-message");
divAlertMessageError.AddCssClass("block-message");
divAlertMessageError.AddCssClass("error");
divAlertMessageError.MergeAttribute("data-valmsg-summary", "true");
divAlertMessageError.MergeAttribute("data-alert", "alert");
TagBuilder hrefClose = new TagBuilder("a");
hrefClose.AddCssClass("close");
hrefClose.InnerHtml = "×";
TagBuilder pSummaryContainer = new TagBuilder("p");
pSummaryContainer.InnerHtml = originalValidation.ToString();
divAlertMessageErrorContainer.Append(hrefClose);
divAlertMessageErrorContainer.Append(pSummaryContainer);
divAlertMessageError.InnerHtml = divAlertMessageErrorContainer.ToString();
return divAlertMessageError.ToMvcHtmlString(TagRenderMode.Normal);
}
示例2: VipSoftActionLink
public static MvcHtmlString VipSoftActionLink(this HtmlHelper htmlHelper, string linkText, string href, string className)
{
var builder = new TagBuilder("a");
builder.InnerHtml = linkText;
builder.MergeAttribute("href", href);
builder.MergeAttribute("class", className);
return builder.ToMvcHtmlString(TagRenderMode.Normal);
}
示例3: IcoLink
public static MvcHtmlString IcoLink(this HtmlHelper htmlHelper, string linkText, string href, string className)
{
var builder = new TagBuilder("a");
builder.InnerHtml = string.Format("<span><b class=\"{1}\">{0}</b></span>", linkText, className);
builder.MergeAttribute("href", href);
builder.MergeAttribute("class", "tools_btn");
return builder.ToMvcHtmlString(TagRenderMode.Normal);
}
示例4: SaveButton
public static MvcHtmlString SaveButton(this HtmlHelper htmlHelper)
{
TagBuilder buttonBuilder = new TagBuilder("input");
buttonBuilder.MergeAttribute("type", "submit");
buttonBuilder.MergeAttribute("value", Labels.Save);
buttonBuilder.MergeAttribute("data-action", "save");
buttonBuilder.AddCssClass("button save");
return buttonBuilder.ToMvcHtmlString(TagRenderMode.SelfClosing);
}
示例5: Submit
public static MvcHtmlString Submit(this HtmlHelper htmlHelper, string submitText)
{
TagBuilder buttonBuilder = new TagBuilder("input");
buttonBuilder.MergeAttribute("type", "submit");
buttonBuilder.MergeAttribute("value", submitText);
buttonBuilder.MergeAttribute("data-action", "submit");
buttonBuilder.AddCssClass("button submit");
return buttonBuilder.ToMvcHtmlString(TagRenderMode.SelfClosing);
}
示例6: Span
public static MvcHtmlString Span(this HtmlHelper helper, string strId, string strContent, object htmlAttributes)
{
var objects = ((IDictionary<string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
var tagBuilder = new TagBuilder("span");
if (string.IsNullOrEmpty(strId)) tagBuilder.MergeAttribute("id", strId);
tagBuilder.SetInnerText(strContent);
tagBuilder.MergeAttributes<string, object>(objects);
return tagBuilder.ToMvcHtmlString(TagRenderMode.Normal);
}
示例7: IcoClick
/// <summary>
/// 带onclick事件的A标签
/// </summary>
/// <param name="linkText">显示名</param>
/// <param name="onclick">事件方法</param>
/// <param name="className">样式</param>
/// <returns></returns>
public static MvcHtmlString IcoClick(this HtmlHelper htmlHelper, string linkText, string onclick, string className)
{
TagBuilder builder = new TagBuilder("a");
builder.InnerHtml = string.Format("<span><b class=\"{1}\">{0}</b></span>", linkText, className);
IDictionary<string,string> dicAttribute=new Dictionary<string, string>();
dicAttribute.Add("href","javascript:;");
dicAttribute.Add("onclick", onclick);
dicAttribute.Add("class", "tools_btn");
builder.MergeAttributes(dicAttribute);
return builder.ToMvcHtmlString(TagRenderMode.Normal);
}
示例8: RenderLabel
private static IHtmlString RenderLabel(
HtmlHelper html,
string htmlFieldName,
string innerText = null,
IDictionary<string, object> htmlAttributes = null)
{
var tagBuilder = new TagBuilder("label");
tagBuilder.Attributes.Add("for", TagBuilder.CreateSanitizedId(html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName)));
tagBuilder.InnerHtml = innerText;
tagBuilder.MergeAttributes(htmlAttributes, true);
return tagBuilder.ToMvcHtmlString(TagRenderMode.Normal);
}
示例9: StateImage
public static MvcHtmlString StateImage(this HtmlHelper htmlHelper, bool status)
{
UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
string statusName = status.ToString();
string imageSrc = urlHelper.Content("~/Images/Status/" + statusName + ".png");
string imageAlt = Display.ResourceManager.GetString(statusName);
TagBuilder tagBuilder = new TagBuilder("img");
tagBuilder.MergeAttribute("src", imageSrc);
tagBuilder.MergeAttribute("alt", imageAlt);
tagBuilder.MergeAttribute("title", imageAlt);
return tagBuilder.ToMvcHtmlString(TagRenderMode.SelfClosing);
}
示例10: LabelHelper
/// <summary>
/// Creates the label HTML.
/// </summary>
public static MvcHtmlString LabelHelper(HtmlHelper html,
ModelMetadata metadata,
string htmlFieldName,
string labelText,
IDictionary<string, object> htmlAttributes)
{
string str = labelText ?? (metadata.DisplayName ?? (metadata.PropertyName ?? htmlFieldName.Split(new[] {'.'}).Last()));
if ( String.IsNullOrEmpty(str) )
{
return MvcHtmlString.Empty;
}
var tagBuilder = new TagBuilder("label") {InnerHtml = html.Encode(str)};
tagBuilder.Attributes.Add("for", TagBuilder.CreateSanitizedId(html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName)));
tagBuilder.MergeAttributes(htmlAttributes, true);
return tagBuilder.ToMvcHtmlString(TagRenderMode.Normal);
}
示例11: Breadcrumbs
/// <summary>
///
/// </summary>
/// <param name="htmlHelper"></param>
/// <param name="menu"></param>
/// <returns></returns>
public static MvcHtmlString Breadcrumbs(this HtmlHelper htmlHelper, Menu menu, string separator = ">>")
{
MenuItem item = menu.Items.FirstOrDefault(x => x.Items, x => x.IsCurrent);
if (item != null)
{
List<KeyValuePair<string, string>> crumbs = new List<KeyValuePair<string, string>>();
UrlHelper url = new UrlHelper(htmlHelper.ViewContext.RequestContext);
while (item != null)
{
KeyValuePair<string, string> link = new KeyValuePair<string, string>(item.Title,
url.Action(item.Action, item.Controller, new RouteValueDictionary(item.RoutesValues)));
crumbs.Add(link);
item = item.Parent;
}
TagBuilder span = new TagBuilder("span");
for (int i = crumbs.Count - 1; i >= 0; i--)
{
TagBuilder linkTag = new TagBuilder("a");
linkTag.InnerHtml = crumbs[i].Key;
linkTag.MergeAttribute("title", crumbs[i].Key);
linkTag.MergeAttribute("href", crumbs[i].Value);
if (i > 0)
{
span.InnerHtml += linkTag.ToString() + " " + separator + " ";
}
else
{
span.InnerHtml += linkTag.ToString();
}
}
return span.ToMvcHtmlString();
}
return MvcHtmlString.Empty;
}
示例12: GritterFlashMessages
public static MvcHtmlString GritterFlashMessages(this HtmlHelper htmlHelper)
{
Flash flash = new Flash(htmlHelper.ViewContext.TempData);
TagBuilder gritterScript = new TagBuilder("script");
StringBuilder messagesBuilder = new StringBuilder("$(function(){");
messagesBuilder.AppendLine();
foreach (var fm in flash.MessagesWithCategories)
{
messagesBuilder.AppendLine(@"$.gritter.add({
title: '" + Labels.ActionResult + @"',
text: '" + (fm.Value as string) + @"',
class_name: 'message " + fm.Key + @"'
});
");
}
messagesBuilder.Append("});");
messagesBuilder.AppendLine();
gritterScript.MergeAttribute("type", "text/javascript");
gritterScript.InnerHtml = messagesBuilder.ToString();
return gritterScript.ToMvcHtmlString();
}
示例13: GetHelpSpan
/// <summary>
/// Gets the help span.
/// </summary>
/// <param name="message">The message.</param>
/// <returns>An MvcHtmlString</returns>
internal static MvcHtmlString GetHelpSpan(string message)
{
if (string.IsNullOrEmpty(message))
{
return new MvcHtmlString(string.Empty);
}
TagBuilder s = new TagBuilder("p");
s.AddCssClass("help-block");
s.InnerHtml = message;
return s.ToMvcHtmlString();
}
示例14: SelectInternal
private static MvcHtmlString SelectInternal(this HtmlHelper htmlHelper, string optionLabel, string name, IEnumerable<SelectListItem> selectList, bool allowMultiple, IDictionary<string, object> htmlAttributes) {
name = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);
if (String.IsNullOrEmpty(name)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "name");
}
bool usedViewData = false;
// If we got a null selectList, try to use ViewData to get the list of items.
if (selectList == null) {
selectList = htmlHelper.GetSelectData(name);
usedViewData = true;
}
object defaultValue = (allowMultiple) ? htmlHelper.GetModelStateValue(name, typeof(string[])) : htmlHelper.GetModelStateValue(name, typeof(string));
// If we haven't already used ViewData to get the entire list of items then we need to
// use the ViewData-supplied value before using the parameter-supplied value.
if (!usedViewData) {
if (defaultValue == null) {
defaultValue = htmlHelper.ViewData.Eval(name);
}
}
if (defaultValue != null) {
IEnumerable defaultValues = (allowMultiple) ? defaultValue as IEnumerable : new[] { defaultValue };
IEnumerable<string> values = from object value in defaultValues select Convert.ToString(value, CultureInfo.CurrentCulture);
HashSet<string> selectedValues = new HashSet<string>(values, StringComparer.OrdinalIgnoreCase);
List<SelectListItem> newSelectList = new List<SelectListItem>();
foreach (SelectListItem item in selectList) {
item.Selected = (item.Value != null) ? selectedValues.Contains(item.Value) : selectedValues.Contains(item.Text);
newSelectList.Add(item);
}
selectList = newSelectList;
}
// Convert each ListItem to an <option> tag
StringBuilder listItemBuilder = new StringBuilder();
// Make optionLabel the first item that gets rendered.
if (optionLabel != null) {
listItemBuilder.AppendLine(ListItemToOption(new SelectListItem() { Text = optionLabel, Value = String.Empty, Selected = false }));
}
foreach (SelectListItem item in selectList) {
listItemBuilder.AppendLine(ListItemToOption(item));
}
TagBuilder tagBuilder = new TagBuilder("select") {
InnerHtml = listItemBuilder.ToString()
};
tagBuilder.MergeAttributes(htmlAttributes);
tagBuilder.MergeAttribute("name", name, true /* replaceExisting */);
tagBuilder.GenerateId(name);
if (allowMultiple) {
tagBuilder.MergeAttribute("multiple", "multiple");
}
// If there are any errors for a named field, we add the css attribute.
ModelState modelState;
if (htmlHelper.ViewData.ModelState.TryGetValue(name, out modelState)) {
if (modelState.Errors.Count > 0) {
tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName);
}
}
return tagBuilder.ToMvcHtmlString(TagRenderMode.Normal);
}
示例15: RenderListBox
private TagBuilder RenderListBox(FormElement formElement)
{
var value = formElement.FieldValue as IList<string>;
var itemsList = formElement.CollectionInfo.CollectionObject;
var tagbuilder = new TagBuilder("select");
tagbuilder.MergeAttribute(HtmlAtrributes.Name, formElement.ControlSpecs.ControlName);
tagbuilder.MergeAttribute(HtmlAtrributes.Id, formElement.ControlSpecs.ClientId);
tagbuilder.MergeAttribute(HtmlAtrributes.Multiple, null);
tagbuilder.MergeAttribute(HtmlAtrributes.Size, formElement.ControlSpecs.Size.ToString());
if (!string.IsNullOrEmpty(formElement.CollectionInfo.SelectPromptLabel))
{
var option = new TagBuilder("option");
option.MergeAttribute(HtmlAtrributes.Value, formElement.CollectionInfo.SelectPromptValue);
option.SetInnerText(formElement.CollectionInfo.SelectPromptLabel);
if (value == null ||
(formElement.CollectionInfo.SelectPromptValue != null
&& formElement.CollectionInfo.SelectPromptValue.ToUpper() == value.ToString().ToUpper())
)
{
option.MergeAttribute(HtmlAtrributes.Selected, null);
}
tagbuilder.InnerHtml += option.ToMvcHtmlString(TagRenderMode.Normal);
}
if (itemsList != null)
{
foreach (var selectListItem in itemsList)
{
var option = new TagBuilder("option");
option.MergeAttribute(HtmlAtrributes.Value, selectListItem.Value);
option.SetInnerText(selectListItem.Text);
if (value != null && value.Contains(selectListItem.Value.ToUpper()))
{
option.MergeAttribute(HtmlAtrributes.Selected, null);
}
tagbuilder.InnerHtml += option.ToMvcHtmlString(TagRenderMode.Normal);
}
}
return tagbuilder;
}