Steve Macculan
Steve Macculan

Reputation: 2322

Nice format of string containing HTML with ASP.NET MVC

I've got string containing HTML code e.g.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><title>Home Page - My ASP.NET MVC Application</title>

and want to display it on page as formatted text e.g.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Home Page - My ASP.NET MVC Application</title>

The HTML string is coming from DownloadString method of WebClient. It will be nice to format it in the same way Firefox -> View Page Source working.

How can I achieve it?

Upvotes: 0

Views: 199

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039428

Don't bother with that. The way you have it is more optimized => it contains less whitespaces => less bandwidth and faster page load times for the end user. Remember that HTML is meant to be read and interpreted by browsers, not by humans. What should count for you is the end result displayed in the browser which is absolutely the same.

So really my advice is don't waste your time in useless optimizations that would actually make things worse.

Of course if you are some maniac purist which absolutely wants to have HTML formatted this way you could use the HTML Agility Pack library or some other parser such as an XDocument (assuming it is valid XHTML) to format it the way you want. But bear in mind that you would have wasted lots of CPU cycles for this useless thing.

Upvotes: 1

Related Questions