The inner text is HTML encoded, so you can't add additional formatting tags if that's what you want to do. If you want an explicit newline in the output, you can do something like
I want to create a html helper class (or extension mathod) to create nicely formatted multiline html output similar to Visual Studio's X(HT)ML editor (when I press Ctrl+K, Ctrl+F it formats xml/code/css... nicely). Is there any class in .NET to make this
happen, or are you planning to add that kind of functionality to MVC framework?
The MVC framework wouldn't really be an appropriate place for us to put such a class, so I wouldn't bet on us adding this functionality any time soon. Have you tried the existing
HtmlTextWriter class? It doesn't sound like it's exactly what you need, but it could get you started.
Marked as answer by Eilon on Jan 30, 2009 01:00 AM
ersoyha
0 Points
2 Posts
TagBuilder's InnerHtml formatting?
Jan 29, 2009 07:12 PM|LINK
Hi.
Is there any simple way to add lines/tabs/spaces to TagBuilder's InnerHtml property to create nicely formatted html output?
Thanks.
Ersoy
ASP.NET mvc HTML Helpers html html formatting TagBuilder
MikaelAhlen
Member
34 Points
8 Posts
Re: TagBuilder's InnerHtml formatting?
Jan 29, 2009 08:32 PM|LINK
Hi,
You can use the \r \n and \t to format the string to do new lines and tabs in the html code.
Like
TagBuilder tb = new TagBuilder("pre"); tb.InnerHtml = "Hello\tWorld"; // That's equal to <pre>Hello(tab)World</pre>Maybe I understood you wrong?jeloff
Contributor
2493 Points
432 Posts
Microsoft
Re: TagBuilder's InnerHtml formatting?
Jan 29, 2009 08:33 PM|LINK
Hi Esroy
The inner text is HTML encoded, so you can't add additional formatting tags if that's what you want to do. If you want an explicit newline in the output, you can do something like
<%
= Html.ActionLink("Foo"+Environment.NewLine, "Bar") %>which will render
<a href="Home/Bar">Foo
</a>
instead of <a href="Home/Bar">Foo</a>
Jacques
ersoyha
0 Points
2 Posts
Re: TagBuilder's InnerHtml formatting?
Jan 29, 2009 10:43 PM|LINK
Hi Jacques, hi Mikael;
I want to create a html helper class (or extension mathod) to create nicely formatted multiline html output similar to Visual Studio's X(HT)ML editor (when I press Ctrl+K, Ctrl+F it formats xml/code/css... nicely). Is there any class in .NET to make this happen, or are you planning to add that kind of functionality to MVC framework?
Thanks for quick reply.
Ersoy
levib
Star
7702 Points
1099 Posts
Microsoft
Re: TagBuilder's InnerHtml formatting?
Jan 29, 2009 10:55 PM|LINK