Change HTML output in MVC3

In my MVC3 application, I want to remove all HTML5 tags for output when the user uses IE <9 to avoid using a workaround in the interface.

I have considered the use of the method HttpModule, ActionFilter, OnResultExecutedon the controller and inside Application_Start.

I figured out that I needed 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 an answer using context.Response.Write.

Reporting about SO and google, MVC does not seem to have the same “page life cycle” that it has web forms (where I just overflow Render, and it works great), which makes sense.

So my question is: how to get HTML as a string in MVC? Has anyone tried to manipulate html output?

+3
source share
4 answers

I think you should use ActionFilter for this. I saw an example of someone modifying the output in this blog post or this post .

+7
source

HTML5 supports backward compatibility, so you can use this default output more in any browser. Outdated browsers like IE6 will display correctly, and even unobtrusive checking will work. Therefore, my advice is to leave the conclusion as it is.

+3
source

javascript? , html, . JQuery .

0

To follow the concept of the MVC pattern, I would like to use a different implementation of the view, depending on whether the browser supports HTML 5 or not, rather than trying to print output. An alternative would be to use controls through a third-party library, which can decompose gracefully when the browser does not support all the latest functions (or the library can implement the controls on its own). The jQuery shipped with ASP.NET MVC is ideal for the many controls available that cover most HTML5 tags.

0
source

Source: https://habr.com/ru/post/1787935/


All Articles