views:

40

answers:

4

Hey There

I am using ASP.NET-MVC, and would like to format my html prior to sending it to the browser.

I have one page with multiple partialviews, and i want it all to be indented nicely.

I know this is stupid, but while in development it's nice to have well formatted html when you go: RightClick -> View Source.

Does anyone know of a way to do this?

+1  A: 

I don't know if this is possible - it certainly does not seem practical - it would be a lot of formatting work on every page when you will only occasionally use view source.

I would suggest selecting a different text editor to do your view source, and then use the editor's formatting tools to format the html. I use TextPad and while the html formatting isn't fabulous, it does help. I am sure there are other editors you could try for this.

Ray
i am loading partial views.. so code blocks sits in different pages
Dusty Roberts
sure, but when it all comes down to the browser, and you do 'view source' - it is all in on place
Ray
in place yes, formatted no. DAve's answer is exactly what i wanted. thanx
Dusty Roberts
I'm glad you found what you need - my suggestion was to format after the fact - rather than format every page that the server serves, you can format -after- you do the 'view source' - you get what you need without the server load
Ray
i follow :) ... and it is more practical to install a text viewer, i subsiquintly installed TextPad, thanx for pointing it out.
Dusty Roberts
A: 

In Java, there the HTML Tidy/JTidy is for. There are ports available in PHP and ASP.NET as well.

BalusC
+1  A: 

Have a look at this blog post: ASP.NET MVC clean HTML

I think it's exactly what you're looking for. The author uses ActionFilters and Tidy.NET to format the HTML output.

Dave
This is 100% spot on, thanx a million
Dusty Roberts
A: 

You can either inject code that gets executed every single request, with attendant risks or overhead. Or you could get better tools.

Wyatt Barnett