Reputation: 17617
In my MVC3 application I want to remove all HTML5 tags for the output when the user is using IE < 9 to avoid using a frontend workaround.
I've looked in to using a HttpModule
, ActionFilter
, the OnResultExecuted
method on a controller and inside Application_Start
.
I've figured so far that I need to get the output as a string from HttpApplication.Context.Response.OutputStream
using something like:
HttpApplication application = (HttpApplication)source;
HttpResponse response = application.Context.Response;
StreamReader sr = new StreamReader(stream);
string content = sr.ReadToEnd();
But all I get is the same error Stream was not readable
.
I can write to the response with context.Response.Write
.
From reading around on SO and google, MVC doesn't seem to have the same "page life cycle" has webforms(where I'm just overring Render
and it works fine) which makes sens.
So my question is how do I get the HTML as a String in MVC? Have anyone tried to manipulate the html output?
Upvotes: 3
Views: 2179
Reputation: 25339
I think you should be able to use an ActionFilter to do this. I've seen an example of someone modifying the output stream in this blog post. or in this post.
Upvotes: 7
Reputation: 1038710
HTML5 is backwards compatible so feel more than free to use this default output with any browser. Obsolete browsers such as IE6 would still render correctly and even unobtrusive validation is going to work. So my advice is to leave the output as is.
Upvotes: 3
Reputation: 43064
To follow the concept of the MVC pattern, I'd look to use a different View implementation depending on whether the browser supports HTML 5 or not rather than trying to bodge the output. An alternative would be to use controls through a third party library that can decompose gracefully when the browser doesn't support all the latest features (or the library can implement the controls independently). JQuery, as supplied with ASP.NET MVC is an ideal with many, many controls available that cover most HTML5 tags.
Upvotes: 0
Reputation: 3216
Why dont you use javascript? Just determine what is user browser and remove html you want. JQuery has nice methods to do that.
Upvotes: 0