Display String Representation in ASP.NET MVC 2

We need to map the ActionResult to string to add pages to our internal search engine index. We settled on this solution to display the string .

I am having a problem with an ExecuteResult call used to process a view.

Code snippet:

 var oldController = controllerContext.RouteData.Values["controller"]; controllerContext.RouteData.Values["controller"] = typeof(TController).Name.Replace("Controller", ""); viewResult.ExecuteResult(controllerContext); // this line breaks 

I get the following error:

"Object reference not set to instance of object" error.

I have confirmed that viewResult not null, so an exception must be ExecuteResult inside ExecuteResult .

What can we lose?

+5
c # asp.net-mvc
source share
4 answers

I get it. The problem with ExecuteResult did not work properly, because I did not make fun of ControllerContext properly. I was able to solve the problem by mocking the controller content as described in this SO-mail:

Mocking Asp.net-mvc Controller Context

Hope this post helps someone in the future if they try to do something like this.

+2
source share

I have not tried this myself, but Phil Haack suggested a way to output the view to a string here, given MVC.

0
source share

MVCContrib has a BlockRenderer class that may be useful for this scenario.

0
source share

This is not a direct answer to your question, but why would you display the entire view as a string in your search index, and not a) by clicking the data itself in the index (LINQ to Lucene allows you to do this w / attributes) or b) unloading the work into a separate a process that bypasses an external interface using a set of rights?

0
source share

All Articles