Eric Wang
Eric Wang

Reputation: 23

ASP.NET MVC, How to get the page content before render

In ASP.NET MVC, how to get the page content before render, we know in Web form app, we can override the method

protected override void Render(HtmlTextWriter writer)

to get the page content before render. but in MVC there are no event concept, so how we can get the page content. the purpose for that is to emphasize(wrap <strong> tag) the keywords before the page rendered. I'd appreciate for any advice. Thank you.

Upvotes: 1

Views: 2687

Answers (1)

ckramer
ckramer

Reputation: 9443

Have a look at this question. The question itself is dealing with filtering content that has been cached, but the approach used by the person asking the question should work for what you are wanting to do.

Basically, you want to create a result filter attribute, and then in the OnResultExecuted method of the attribute add a Response Filter. Not sure what the specifics of the filter would be in your case...probably setting up some sort of regex replace for the keywords that would wrap them in tags.

Another possible way to handle this would be client side using some cleaver jQuery action. If you could get the list of keywords in an array, then you could use a regex on the client side to do the same sort of thing. (Sorry, it's late right now, and the code sample is not coming to me. If you would like a code sample I may be able to hook you up in the morning :))

Upvotes: 2

Related Questions