Questions tagged [tagbuilder]

36 questions
41
votes
6 answers

Why use TagBuilder instead of StringBuilder?

what's the difference in using tag builder and string builder to create a table in a htmlhelper class, or using the HtmlTable? aren't they generating the same thing??
DaveDev
  • 38,095
  • 68
  • 199
  • 359
28
votes
3 answers

Nested TagBuilder -as TagBuilderTree-

TagBuilder is a nice implementation for build HTML elements. But -some- HTML elements can have another elements (I called like children). I could not find any class from Mvc classes. Question; Should I implement few classes (TagBuilderTree, and…
Nuri YILMAZ
  • 4,183
  • 5
  • 33
  • 41
6
votes
2 answers

TagBuilder.MergeAttributes does not work

I am creating my own helper in MVC. But the custom attributes are not added in the HTML: Helper public static MvcHtmlString MenuItem(this HtmlHelper helper, string linkText, string actionName, string controllerName, object htmlAttributes) { var…
ridermansb
  • 9,589
  • 20
  • 104
  • 197
6
votes
1 answer

How to load a partialview and store it in a variable to be used in javascript?

I have a prtialview using a model to create a dropdown list. In my main view I create the partialview html string to use it in javascript functions later. View: @model SomeViewModel @{ var devicesDropDown = @Html.Partial("_DropDown",…
5
votes
3 answers

Can you control the order in which the TagBuilder class renders attributes?

I know this is kind of obsessive, but is there a way to control the order that the TagBuilder class renders the attributes of an HTML tag when you call ToString()? i.e. so that var tb = new TagBuilder("meta"); …
Glenn Slaven
  • 31,855
  • 25
  • 107
  • 163
5
votes
2 answers

Html.ActionLink extension

I am trying to extend the Html.ActionLink as I want to add a custom meta data for a shared component (in this case a modal). My aim is to further extend the LinkExtensions class within .Net MVC which will add a value to the html class attribute and…
Andy Clark
  • 3,133
  • 7
  • 24
  • 41
4
votes
2 answers

TagBuilder add attribute without value

The same question from here. How to add attribute without value This time, I want to create an input with AngularJS attribute, to use it as a directive. Here is what I want: This is what the TagBuilder generated:
Huy Hoang Pham
  • 3,972
  • 1
  • 13
  • 26
4
votes
3 answers

What is the difference, if any, between string.Format and TagBuilder in ASP.NET MVC?

I have a Html Helper file for my ASP.NET MVC application. The majority of them simply return a formatted string. Here is an example of one of my formatted string helpers: public static string Label(this HtmlHelper helper, string @for, string…
Anders
  • 11,090
  • 34
  • 91
  • 142
3
votes
1 answer

ASP.NET MVC - Unit testing HTML that is generated by TagBuilders

I have code that generates html via TagBuilders How could I test if the right HTML is generated? My TagBuilder is not as simple as just one tag, it also contains other tags. So I have a function that returns TagBuilder object with following…
dev.e.loper
  • 34,180
  • 71
  • 151
  • 237
3
votes
1 answer

Net Core: Use a Tag Helper in a Custom Tag Helper that returns Html?

I am trying to conduct this question except in .Net Core 2. Can I use a Tag Helper in a custom Tag Helper that returns html? " I would like to use a tag helper within a tag helper. I looked around and couldn't find anyone else trying to do this, am…
3
votes
1 answer

Prevent TagBuilder.MergeAttribute from encoding attribute text

I've created a Html helper that encodes email addresses in order to prevent SPAM. This is the same technique used by the MarkdownSharp library when auto-generating email links. The problem is that TagBuilder.MergeAttribute encodes the attribute text…
Ben Foster
  • 32,767
  • 35
  • 157
  • 274
3
votes
2 answers

ASP.NET MVC TagBuilder.SetInnerText() not setting the text correctly

So I am creating a HtmlHelper extension method and I have run into a problem when using TagBuilder.SetInnerText(). The helper outputs an option tag. Here is the source of the helper: public static string Option(this HtmlHelper helper, string…
Tim Banks
  • 6,842
  • 4
  • 29
  • 27
2
votes
1 answer

Disable HTML encoding of attribute values in TagBuilder

I'm using MVC and I've created a HtmlHelper extension function ImageLink. This function uses two TagBuilder objects to build an HTML image link (like ). It works fine, but now I have a page on which the action for the image button…
Jasper
  • 1,537
  • 1
  • 18
  • 45
2
votes
2 answers

Asp.NET MVC 6, TagHelper "asp-for" to Model itself

Lets say I have this partial View: @model DateTime? What goes to ??? to bind to the Model its self?
Skorunka František
  • 4,094
  • 4
  • 36
  • 63
2
votes
2 answers

asp.net MVC6 Implementing a tagbuilder class and get error on ".ToString"

I am getting compile errors when attempting to implement the message class from Levelnis's Blog. The class in question is: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using…
si2030
  • 2,799
  • 4
  • 25
  • 60
1
2 3