本文整理汇总了C#中TagBuilder.SetInnerText方法的典型用法代码示例。如果您正苦于以下问题:C# TagBuilder.SetInnerText方法的具体用法?C# TagBuilder.SetInnerText怎么用?C# TagBuilder.SetInnerText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TagBuilder
的用法示例。
在下文中一共展示了TagBuilder.SetInnerText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: checaCategorizacion
/// <summary>
/// Revisa si el padre de la categoria aun esta disponible en la base de datos,
///
/// <para>De ser asi, se muestra el nombre del padre de lo contrario se muestra el mensaje "no categorizada"</para>
/// <para>De ser root se muestra el mensaje root o categoria raíz</para>
/// </summary>
/// <param name="helper"></param>
/// <param name="idPadre"></param>
/// <returns></returns>
public static IHtmlString checaCategorizacion(this HtmlHelper helper, int idPadre)
{
IRepositorioBase<Categoria> _categoria = new RepositorioCategorias(new DataContext());
var categoriaPadre = _categoria.CargarPorId(idPadre);
TagBuilder span = new TagBuilder("span");
if (categoriaPadre != null)
{
span.MergeAttribute("class", "label label-success");
span.SetInnerText(categoriaPadre.nombreCategoria);
}
else
{
if (idPadre == 0)
{
span.MergeAttribute("class", "label label-info");
span.SetInnerText("Padre");
}
else
{
span.MergeAttribute("class", "label label-danger");
span.SetInnerText("Categoria padre no encontrada");
}
}
return new HtmlString(span.ToString());
}
示例2: Pagination
public static MvcHtmlString Pagination(this HtmlHelper html, PagingInfo pagingInfo, Func<int, int, string> pageUrl)
{
TagBuilder pagingUl = new TagBuilder("ul");
pagingUl.AddCssClass("pagination");
for (int i = 1; i <= pagingInfo.TotalPages; i++)
{
TagBuilder li = new TagBuilder("li");
TagBuilder a = new TagBuilder("a");
a.MergeAttribute("href", pageUrl(i, pagingInfo.ItemsPerPage));
a.SetInnerText(i.ToString());
if (i == pagingInfo.CurrentPage)
li.AddCssClass("active");
li.InnerHtml += a;
pagingUl.InnerHtml += li;
}
TagBuilder pagingSettingsUl = new TagBuilder("ul");
pagingSettingsUl.AddCssClass("pager");
for (int i = 0; i <= 4; i++)
{
TagBuilder li = new TagBuilder("li");
TagBuilder a = new TagBuilder("a");
if (i == 0)
{
a.MergeAttribute("href", pageUrl(1, int.MaxValue));
a.SetInnerText("All");
}
else
{
a.MergeAttribute("href", pageUrl(1, i * 12));
a.SetInnerText((i * 12).ToString());
}
if (i * 12 == pagingInfo.ItemsPerPage || (i == 0 && pagingInfo.ItemsPerPage == int.MaxValue))
{
a.AddCssClass("text-primary");
a.MergeAttribute("style", "text-decoration:underline");
}
li.InnerHtml += a;
pagingSettingsUl.InnerHtml += li;
}
return MvcHtmlString.Create(pagingUl.ToString() + pagingSettingsUl.ToString());
}
示例3: mostrarCategoria
public static IHtmlString mostrarCategoria(this HtmlHelper helper,Categoria categoria)
{
TagBuilder span = new TagBuilder("span");
if (categoria!=null)
{
span.MergeAttribute("class", "label label-success");
span.SetInnerText(categoria.nombreCategoria);
}
else
{
span.MergeAttribute("class", "label label-danger");
span.SetInnerText("No categorizado");
}
return new HtmlString(span.ToString());
}
示例4: ParseTags
public static MvcHtmlString ParseTags(this HtmlHelper html, string description)
{
string result = "";
for (int i = 0; i < description.Length; ++i)
{
if (description[i] == '#')
{
++i;
string href = "/Search/Find/";
string text = "";
while (i < description.Length && description[i] != ' ' && description[i] != '#')
{
text += description[i++];
}
href += text;
TagBuilder a = new TagBuilder("a");
a.MergeAttribute("href", href);
a.SetInnerText("#" + text);
result += a.ToString();
--i;
}
else
{
result += description[i];
}
}
return new MvcHtmlString(result);
}
示例5: ValidationSummaryBox
public static string ValidationSummaryBox(this HtmlHelper htmlHelper, string message)
{
if (htmlHelper.ViewData.ModelState.IsValid)
return null;
TagBuilder divBuilder = new TagBuilder("div");
divBuilder.Attributes["id"] = "errors";
if (!string.IsNullOrEmpty(message))
{
TagBuilder messageBuilder = new TagBuilder("p");
messageBuilder.SetInnerText(message);
divBuilder.InnerHtml += messageBuilder.ToString(TagRenderMode.Normal) + Environment.NewLine;
}
StringBuilder builder = new StringBuilder();
TagBuilder listBuilder = new TagBuilder("ul");
foreach (ModelState state in htmlHelper.ViewData.ModelState.Values)
{
foreach (ModelError error in state.Errors)
{
string errorMessage = GetUserErrorMessageOrDefault(htmlHelper.ViewContext.HttpContext, error, null);
if (!string.IsNullOrEmpty(errorMessage))
{
TagBuilder liBuilder = new TagBuilder("li");
liBuilder.SetInnerText(errorMessage);
builder.AppendLine(liBuilder.ToString(TagRenderMode.Normal));
}
}
}
listBuilder.InnerHtml = builder.ToString();
divBuilder.InnerHtml += listBuilder.ToString(TagRenderMode.Normal);
return divBuilder.ToString(TagRenderMode.Normal);
}
示例6: 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;
}
示例7: Render
public MvcHtmlString Render()
{
var container = new TagBuilder("div");
container.AddCssClass("flash-holder");
if (!string.IsNullOrWhiteSpace(Message))
{
var flash = new TagBuilder("div");
switch (Priority)
{
case FlashPriority.General:
flash.AddCssClass("general");
break;
case FlashPriority.Success:
flash.AddCssClass("success");
break;
case FlashPriority.Error:
flash.AddCssClass("error");
break;
}
flash.SetInnerText(Message);
container.InnerHtml = flash.ToString();
}
return MvcHtmlString.Create(container.ToString());
}
示例8: SelectEmpresa
public static MvcHtmlString SelectEmpresa(this HtmlHelper html, int idEmpresa = 0, bool todas = false)
{
var empresas = new EmpresaService().Listar()
.Where(x => x.Ativo == true)
.OrderBy(x => x.Fantasia)
.ToList();
TagBuilder tag = new TagBuilder("select");
tag.MergeAttribute("id", "IdEmpresa");
tag.MergeAttribute("name", "IdEmpresa");
tag.MergeAttribute("class", "form-control");
if (todas == true)
{
TagBuilder itemTag = new TagBuilder("option");
itemTag.MergeAttribute("value", "0");
itemTag.SetInnerText("");
tag.InnerHtml += itemTag.ToString();
}
foreach (var item in empresas)
{
TagBuilder itemTag = new TagBuilder("option");
itemTag.MergeAttribute("value", item.Id.ToString());
if (item.Id == idEmpresa)
{
itemTag.MergeAttribute("selected", "selected");
}
itemTag.SetInnerText(item.Fantasia);
tag.InnerHtml += itemTag.ToString();
}
return new MvcHtmlString(tag.ToString());
}
示例9: 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());
}
示例10: GetAlerts
public static MvcHtmlString GetAlerts(this HtmlHelper helper, AlertType alertType, AlertLocation alertLocation)
{
var alertData = helper.ViewContext.TempData.InitializeAlertData();
List<string> messages = alertData[alertLocation][alertType];
if (messages.Count > 0)
{
var outerBuilder = new TagBuilder("div");
outerBuilder.AddCssClass("container-fluid");
foreach (var message in messages)
{
var builder = new TagBuilder("div");
builder.AddCssClass("alert");
builder.AddCssClass("in");
builder.AddCssClass("fade");
builder.AddCssClass(alertType.GetDescription());
builder.SetInnerText(message);
var closeButton = new TagBuilder("a");
closeButton.AddCssClass("close");
closeButton.MergeAttribute("data-dismiss", "alert");
closeButton.MergeAttribute("href", "#");
closeButton.InnerHtml += "×";
builder.InnerHtml += closeButton.ToString(TagRenderMode.Normal);
outerBuilder.InnerHtml += builder.ToString(TagRenderMode.Normal);
}
return outerBuilder.ToString(TagRenderMode.Normal).ToMvcHtmlString();
}
return string.Empty.ToMvcHtmlString();
}
示例11: Anchor
public static MvcHtmlString Anchor(this HtmlHelper htmlHelper, string linkText, object htmlAttributes)
{
Action<TagBuilder, PropertyInfo> addAttribute = (tb, p) => tb.MergeAttribute(p.Name, p.GetValue(htmlAttributes, null).ToString());
Func<MvcHtmlString> returnEmpty = () =>
{
var tb = new TagBuilder("span");
tb.SetInnerText(linkText);
return MvcHtmlString.Create(tb.ToString());
};
Func<MvcHtmlString> returnAnchor = () =>
{
var tb = new TagBuilder("a");
var props = htmlAttributes.GetType().GetProperties();
foreach (var prop in props)
{
addAttribute(tb, prop);
}
tb.SetInnerText(linkText);
return MvcHtmlString.Create(tb.ToString());
};
Func<object, bool> hrefIsEmpty = (o) => o.GetType().GetProperties().Where(p => p.Name == "href")
.Select(x => x.GetValue(o, null))
.Where(v => v == null)
.Count() == 1;
return hrefIsEmpty(htmlAttributes)
? returnEmpty()
: returnAnchor();
}
开发者ID:passionateprogrammersguild,项目名称:Back-to-Basics-with-ASP.NET-MVC,代码行数:32,代码来源:HtmlHelperExtensions.cs
示例12: Writer
public static void Writer(HtmlHelper htmlHelper, IEnumerable<SelectListItem> collection, IDictionary<string, object> htmlAttributes)
{
var select = new TagBuilder("select");
select.MergeAttributes(htmlAttributes);
var sb = new StringBuilder();
if (collection != null)
{
foreach (var item in collection)
{
var option = new TagBuilder("option");
option.MergeAttribute("value", item.Value);
if (item.Selected)
{
option.MergeAttribute("selected", "selected");
}
option.SetInnerText(item.Text);
sb.AppendLine(option.ToString(TagRenderMode.Normal));
}
}
select.InnerHtml = sb.ToString();
htmlHelper.ViewContext.Writer.Write(select.ToString(TagRenderMode.Normal));
}
示例13: Button
public static IHtmlString Button(this HtmlHelper htmlHelper, string buttonText, string permissions, IDictionary<string, string> attributeDic)
{
var user = SecurityContextHolder.Get();
if (!string.IsNullOrWhiteSpace(permissions))
{
string[] permissionArray = permissions.Split(',');
var q = user.UrlPermissions.Where(p => permissionArray.Contains(p)).ToList();
if (q == null || q.Count() == 0)
{
return MvcHtmlString.Empty;
}
}
var button = new TagBuilder("button");
button.SetInnerText(buttonText);
if (attributeDic.ContainsKey("needconfirm") && bool.Parse(attributeDic["needconfirm"]))
{
if (attributeDic.ContainsKey("onclick"))
{
attributeDic["onclick"] = "if( confirm('" + string.Format(Resources.Global.Button_ConfirmOperation, buttonText) + "')){" + attributeDic["onclick"] + "}";
}
else
{
attributeDic.Add("onclick", "return confirm('" + string.Format(Resources.Global.Button_ConfirmOperation, buttonText) + "');");
}
}
button.MergeAttributes(attributeDic);
return new HtmlString(" " + button.ToString());
}
示例14: SaveButton
public static MvcHtmlString SaveButton(this HtmlHelper helper)
{
var buttonBuilder = new TagBuilder("button");
buttonBuilder.SetInnerText(Cult.SysTexts.Save);
buttonBuilder.AddCssClass("btn");
buttonBuilder.AddCssClass("btn-primary");
buttonBuilder.Attributes.Add("type", "submit");
buttonBuilder.Attributes.Add("id", "saveButton");
var iBuilder = new TagBuilder("i");
iBuilder.AddCssClass("icon-download-alt");
iBuilder.AddCssClass("icon-white");
buttonBuilder.InnerHtml = Environment.NewLine + iBuilder + Environment.NewLine + buttonBuilder.InnerHtml;
var totHtml = buttonBuilder.ToString();
var inputBuilder = new TagBuilder("input");
inputBuilder.Attributes.Add("type", "hidden");
inputBuilder.Attributes.Add("id", "UrlHash");
inputBuilder.Attributes.Add("name", "UrlHash");
var modelEdit = helper.ViewData.Model as ViewModelBase;
inputBuilder.Attributes.Add("value", modelEdit != null ? modelEdit.UrlHash : "");
totHtml += inputBuilder.ToString();
return new MvcHtmlString(totHtml);
}
示例15: CreatePageLink
private string CreatePageLink(int pageNumber, string text)
{
var builder = new TagBuilder("a");
builder.SetInnerText(text);
builder.MergeAttribute("href", urlBuilder(pageNumber));
return builder.ToString(TagRenderMode.Normal);
}