0

I am calling a function that is trying to grab the HTML output from a MVC razor view, and pass me the HTML output as a string.

here's my code:

Dim ControllerContext As New ControllerContext
ControllerContext.RouteData.Values.Add("id", reqID)
ControllerContext.RouteData.Values.Add("controller", "po")
Dim viewResult As ViewEngineResult = ViewEngines.Engines.FindPartialView(ControllerContext, "print")
Dim viewContext As ViewContext = New ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw)
viewResult.View.Render(viewContext, sw)
viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View)

Dim strHTML As String = sw.GetStringBuilder().ToString()

It fails on the line "viewResult.View.Render(viewContext,sw) with the error -- System.NotImplementedException: The method or operation is not implemented.

I really want to be able to call this from a CRON JOB/script. Not only from an MVC page HTTP POST. Maybe that makes a difference? Because, I previously had this working, when it was called from HTTP POST method within the controller. Now, from my script, I'm calling a VB function (that resides in a separate class) that calls this function with the FindPartialView stuff (that resides in my POController).

Craig W.
  • 17,838
  • 6
  • 49
  • 82
paige1025
  • 13
  • 1
  • 4
  • possible duplicate of [Render a view as a string](http://stackoverflow.com/questions/483091/render-a-view-as-a-string) – dotjoe Jul 21 '14 at 14:47
  • I don't see anything about this error there...It fails on the line "viewResult.View.Render(viewContext,sw) with the error -- System.NotImplementedException: The method or operation is not implemented. – paige1025 Jul 21 '14 at 14:59
  • What's your plan for calling this from a script? Will this be running from a webserver and you'll hit the URL using `WebClient` or do you want to compile this as a command line application or ...? Your specific error is that your don't pass in a real `ControllerContext`, this empty `Dim ControllerContext As New ControllerContext` context, just ain't going to fly. – Mark Jul 21 '14 at 17:04
  • instead, doing it properly seemed to work: – paige1025 Jul 21 '14 at 18:11

0 Answers0