asp.net-mvcjsonresultviewcontext

Get the Current ViewContext in ASP.Net MVC


I have a ASP.Net MVC JsonResult function in which I want to return the contents of a PartialView (The content has to be loaded using Ajax, and for some reason I can't return a PartialViewResult).

To render the PartialView I need the ViewContext object.

How do you get the current ViewContext object within an Action method? I don't even see HttpContext.Current in my action method.

I am using ASP.net MVC 1.


Solution

  • a ViewContext is not available within the action method because it is constructed later before rendering the view. I would suggest you using MVCContrib's BlockRenderer to render the contents of a partial view into a string.