本文整理汇总了C#中TagBuilder.AddCssClass方法的典型用法代码示例。如果您正苦于以下问题:C# TagBuilder.AddCssClass方法的具体用法?C# TagBuilder.AddCssClass怎么用?C# TagBuilder.AddCssClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TagBuilder
的用法示例。
在下文中一共展示了TagBuilder.AddCssClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MenuItem
public static string MenuItem(this HtmlHelper helper, string linkText, string actionName, string controllerName, string area)
{
if (Roles.IsUserInRole(ROLES.admin.ToString())
|| controllerName.Equals("Home")
|| controllerName.Equals("AccountTransactions")
|| controllerName.Equals("Message"))
{
var currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
var currentActionName = (string)helper.ViewContext.RouteData.Values["action"];
var builder = new TagBuilder("li");
builder.AddCssClass("ui-state-default ui-corner-top");
// Add selected class
if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase))
builder.AddCssClass("ui-state-active");
// Add link
builder.InnerHtml = helper.ActionLink(linkText, actionName, controllerName, new { area = area }, null).ToHtmlString();
// Render Tag Builder
return builder.ToString(TagRenderMode.Normal);
}
return String.Empty;
}
示例2: AjaxLinkModalWindow
public static MvcHtmlString AjaxLinkModalWindow(
this HtmlHelper htmlHelper,
string linkText,
string targetUrl,
string modalId,
string targetId,
string cssClass,
string iconClass,
string dataGet)
{
var builder = new TagBuilder("a");
builder.SetInnerText(" " + linkText);
builder.Attributes.Add("href", "#");
builder.Attributes.Add("data-target-url", targetUrl);
builder.Attributes.Add("data-target-id", targetId);
builder.Attributes.Add("data-modal-id", modalId);
builder.Attributes.Add("data-get", dataGet);
builder.AddCssClass("ajax-link-modal-window");
builder.AddCssClass(cssClass);
var iconBuilder = new TagBuilder("i");
iconBuilder.AddCssClass(iconClass);
builder.InnerHtml += iconBuilder.ToString();
return new MvcHtmlString(builder.ToString());
}
示例3: ToHtmlString
/// <summary>
/// Renders the div with formgroup class with some html controls inside
/// </summary>
/// <returns></returns>
public string ToHtmlString()
{
var formGroup = new TagBuilder("div");
formGroup.AddCssClass("form-group");
if (!_fieldIsValid)
formGroup.AddCssClass("error");
switch (_type)
{
case FormGroupType.TextBoxLike:
formGroup.InnerHtml = _label + _input.ToHtmlString();
break;
case FormGroupType.CheckBoxLike:
formGroup.InnerHtml = _label.ToHtmlString();
break;
default:
break;
}
return formGroup.ToString();
}
示例4: NavigationListItemRouteLink
public static MvcHtmlString NavigationListItemRouteLink(this HtmlHelper html, NamedRoute route)
{
var li = new TagBuilder("li")
{
InnerHtml = html.RouteLink(route.DisplayName, route.Name).ToString()
};
if (CurrentRouteMatchesName(html, route.Name))
{
li.AddCssClass("active");
}
if (route.Children.Count() > 0)
{
//TODO: create a UL of child routes here.
li.AddCssClass("dropdown");
li.InnerHtml = "<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">" + route.DisplayName +"<b class=\"caret\"></b></a>";
var ul = new TagBuilder("ul");
ul.AddCssClass("dropdown-menu");
foreach (var child in route.Children)
{
var childLi = new TagBuilder("li");
childLi.InnerHtml = html.RouteLink(child.DisplayName, child.Name).ToString();
ul.InnerHtml += childLi.ToString();
}
//that would mean we need to make some quick
li.InnerHtml = "<a href='#' class='dropdown-toggle' data-toggle='dropdown'>"+route.DisplayName + " <b class='caret'></b></a>" + ul.ToString();
}
return MvcHtmlString.Create(li.ToString(TagRenderMode.Normal));
}
示例5: CreateElement
public static MvcHtmlString CreateElement(this HtmlHelper htmlHelper)
{
var allHtml = new TagBuilder("span");
for (int i = 1; i < 6; i++)
{
var divBuilder = new TagBuilder("div");
var divTwoBuilder = new TagBuilder("div");
var spanBuilder = new TagBuilder("span");
var iBuilder = new TagBuilder("i");
if (i == 5) divBuilder.AddCssClass("cssload-last-finger");
else divBuilder.AddCssClass("cssload-finger cssload-finger-" + i);
if (i == 5) divTwoBuilder.AddCssClass("cssload-last-finger-item");
else divTwoBuilder.AddCssClass("cssload-finger-item");
divTwoBuilder.InnerHtml += spanBuilder.ToString() + iBuilder.ToString();
divBuilder.InnerHtml += divTwoBuilder.ToString();
allHtml.InnerHtml += divBuilder;
}
return new MvcHtmlString(allHtml.ToString());
}
示例6: PageLinks
public static MvcHtmlString PageLinks(this HtmlHelper html, PageInfo pageInfo, Func<int, string> pageUrl)
{
StringBuilder result = new StringBuilder();
for (int i = 1; i <= pageInfo.TotalPages; i++)
{
TagBuilder tag = new TagBuilder("a");
tag.MergeAttribute("href", pageUrl(i));
tag.MergeAttribute("data-ajax-update", "#address-cursor-rows");
tag.MergeAttribute("data-ajax-success", "OnSuccess");
tag.MergeAttribute("data-ajax-mode", "replace");
tag.MergeAttribute("data-ajax", "true");
tag.InnerHtml = i.ToString();
// если текущая страница, то выделяем ее, например, добавляя класс
if (i == pageInfo.PageNumber)
{
tag.AddCssClass("selected");
tag.AddCssClass("btn-primary");
}
tag.AddCssClass("btn btn-default");
result.Append(tag.ToString());
}
return MvcHtmlString.Create(result.ToString());
}
示例7: PageLinks
public static MvcHtmlString PageLinks(this HtmlHelper html,
PagingInfo pagingInfo,
Func<int, string> pageUrl)
{
var result = new StringBuilder();
for (int i = 0; i < pagingInfo.TotalPages; i++)
{
var pageNumber = i + 1;
//build anchor
var tag = new TagBuilder("a");
//build the out goin url
tag.MergeAttribute("href", pageUrl(pageNumber));
tag.InnerHtml = pageNumber.ToString();
if (pageNumber == pagingInfo.CurrentPage)
{
//add bootstrap style
tag.AddCssClass("selected");
tag.AddCssClass("btn-primary");
}
else
{
tag.AddCssClass("btn-default");
}
tag.AddCssClass("btn");
result.Append(tag);
}
return MvcHtmlString.Create(result.ToString());
}
示例8: ToHtmlString
public override string ToHtmlString()
{
string innerText = Text ?? string.Empty;
string fullName = Name;
string tagName = TagName.HasValue() ? TagName.ToLower() : "span";
var tagBuilder = new TagBuilder(tagName);
if (Encode)
tagBuilder.SetInnerText(innerText);
else
tagBuilder.InnerHtml = innerText;
tagBuilder.MergeAttributes(HtmlAttributes);
if (fullName.HasValue())
tagBuilder.GenerateId(fullName);
foreach (string cssClass in CssClasses)
tagBuilder.AddCssClass(cssClass);
if (CanWrite())
{
if (GrantedClass.HasValue())
tagBuilder.AddCssClass(GrantedClass);
}
else
{
if (DeniedClass.HasValue())
tagBuilder.AddCssClass(DeniedClass);
}
return tagBuilder.ToString(TagRenderMode.Normal);
}
示例9: Panel
public Panel(HtmlHelper helper, string templateName, params string[] classNames)
{
_helper = helper;
_templateName = templateName;
ViewContext context = helper.ViewContext;
_builder = new TagBuilder("div");
if (classNames == null || classNames.Length == 0)
{
classNames = new[] { "widget" };
}
var includeWidget = false;
foreach (var cls in classNames)
{
if (cls == "widget")
{
includeWidget = true;
}
_builder.AddCssClass(cls);
}
if (!includeWidget)
{
_builder.AddCssClass("widget");
}
context.Writer.Write(_builder.ToString(TagRenderMode.StartTag));
_context = context;
}
示例10: MenuItem
public static MvcHtmlString MenuItem(this HtmlHelper htmlHelper, string text, string action, string controller, int? categoryId = null, string cssClasses = null)
{
var li = new TagBuilder("li");
var routeData = htmlHelper.ViewContext.RouteData;
var currentAction = routeData.GetRequiredString("action");
var currentController = routeData.GetRequiredString("controller");
if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) &&
string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase))
{
li.AddCssClass("active");
}
if (!string.IsNullOrEmpty(cssClasses))
{
li.AddCssClass(cssClasses);
}
if (categoryId != null)
{
li.InnerHtml = htmlHelper.ActionLink(text, action, controller,new { id = categoryId.Value },new {}).ToHtmlString();
}
else
{
li.InnerHtml = htmlHelper.ActionLink(text, action, controller).ToHtmlString();
}
return MvcHtmlString.Create(li.ToString());
}
示例11: CopyButton
public static MvcHtmlString CopyButton(this HtmlHelper helper, string name, string actionName,
string controllerName, object routeValues,
object htmlAttributes)
{
var buttonBuilder = new TagBuilder("button");
buttonBuilder.SetInnerText(name);
buttonBuilder.AddCssClass("btn");
buttonBuilder.AddCssClass("btn-success");
buttonBuilder.Attributes.Add("id", "copyButton");
var iBuilder = new TagBuilder("i");
iBuilder.AddCssClass("icon-camera");
iBuilder.AddCssClass("icon-white");
buttonBuilder.InnerHtml = Environment.NewLine + iBuilder + Environment.NewLine + buttonBuilder.InnerHtml;
var formBuilder = new TagBuilder("form");
var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
var url = urlHelper.Action(actionName, controllerName, routeValues);
url = QuerystringHelper.PropagateModal(url);
formBuilder.Attributes.Add("action", url);
formBuilder.Attributes.Add("method", "POST");
formBuilder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
formBuilder.InnerHtml = Environment.NewLine + buttonBuilder;
return new MvcHtmlString(formBuilder.ToString());
}
示例12: BootstrapTextbox
public static MvcHtmlString BootstrapTextbox(this HtmlHelper htmlHelper, MvcHtmlString htmlTextBox, string prepend, string append)
{
TagBuilder builder = new TagBuilder("div");
if (!string.IsNullOrEmpty(prepend))
{
builder.AddCssClass("input-prepend");
TagBuilder span = new TagBuilder("span");
span.AddCssClass("add-on");
span.InnerHtml += prepend;
builder.InnerHtml += span;
}
builder.InnerHtml += htmlTextBox;
if (!string.IsNullOrEmpty(append))
{
builder.AddCssClass("input-append");
TagBuilder span = new TagBuilder("span");
span.AddCssClass("add-on");
span.InnerHtml += append;
builder.InnerHtml += span;
}
return MvcHtmlString.Create(builder.ToString());
}
示例13: Result
public static MvcHtmlString Result(this HtmlHelper html, string testName, bool isPassed, int result, int amountOfQuestions, int amountOfCorrectQuestions)
{
TagBuilder p = new TagBuilder("p");
string innerText = "Тест \"" + testName + "\" ";
TagBuilder span = new TagBuilder("span");
if (isPassed)
{
span.AddCssClass("passed");
span.InnerHtml = "успешно пройден!";
}
else
{
span.AddCssClass("failed");
span.InnerHtml = "не пройден!";
}
innerText += span.ToString(TagRenderMode.Normal);
p.InnerHtml = innerText;
TagBuilder pRes = new TagBuilder("p");
pRes.InnerHtml = "Правильных ответов: " + amountOfCorrectQuestions + "/" + amountOfQuestions + "(" + result + "%)";
string res = p.ToString() + pRes.ToString();
return MvcHtmlString.Create(res);
}
示例14: PageLinks
public static MvcHtmlString PageLinks(this HtmlHelper html,
PagingInfo pagingInfo,
Func<int, string> pageUrl)
{
var result = new StringBuilder();
for (int i = 1; i <= pagingInfo.TotalPages; i++)
{
var tag = new TagBuilder("a");
tag.MergeAttribute("href", pageUrl(i));
// Func<int, string>
// int here is just the input type, 1 parameter
// string is what is returned.
// <a href="computedFunc pageUrl">
tag.InnerHtml = i.ToString();
//i
if (i == pagingInfo.CurrentPage)
{
tag.AddCssClass("selected");
tag.AddCssClass("btn-primary");
}
tag.AddCssClass("btn btn-default");
result.Append(tag.ToString());
}
return MvcHtmlString.Create(result.ToString());
}
示例15: ToHtmlString
public string ToHtmlString()
{
TagBuilder buttonTag = new TagBuilder(Tag.ToString());
buttonTag.AddCssClass("k-button k-button-icontext td-grid-button");
if (CssClass.HasValue())
buttonTag.AddCssClass(CssClass.Trim());
if (Name.HasValue())
{
buttonTag.MergeAttribute("name", Name);
buttonTag.GenerateId(Name);
}
if (Title.HasValue())
buttonTag.MergeAttribute("title", Title);
if (Tag == ButtonTag.a)
buttonTag.MergeAttribute("href", Url.HasValue() ? Url : "javascript: void(0)");
if (HtmlAttributes.Count > 0)
buttonTag.MergeAttributes(HtmlAttributes);
var imageTag = new TagBuilder("span");
imageTag.AddCssClass("k-icon td-grid-button-image");
if (ImageCssClass.HasValue())
imageTag.AddCssClass(ImageCssClass);
buttonTag.InnerHtml = imageTag.ToString();
return buttonTag.ToString();
}