Rendering a view to a string in ASP.NET MVC 2
Posted
by Frank Rosario
on Stack Overflow
See other posts from Stack Overflow
or by Frank Rosario
Published on 2010-03-16T16:26:10Z
Indexed on
2010/03/26
2:53 UTC
Read the original article
Hit count: 349
We need to render an ActionResult
to a string
to add pages to our internal search engine index. We settled on this solution to render to string.
I've run into a problem with the ExecuteResult
call used to process the 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 receive the following error:
"Object reference not set to instance of object" error.
I've confirmed viewResult
is not null, so the exception has to be thrown internally in ExecuteResult
.
What could we be missing?
© Stack Overflow or respective owner