How to Render Partial View into a String

Posted by DaveDev on Stack Overflow See other posts from Stack Overflow or by DaveDev
Published on 2010-03-29T12:20:23Z Indexed on 2010/03/30 9:43 UTC
Read the original article Hit count: 362

Filed under:
|

Hi all, I have the following code:

public ActionResult SomeAction()
{
    return new JsonpResult
    {
        Data = new { Widget = "some partial html for the widget" }
    };
}

I'd like to modify it so that I could have

public ActionResult SomeAction()
{
    // will render HTML that I can pass to the JSONP result to return.
    var partial = RenderPartial(viewModel); 
    return new JsonpResult
    {
        Data = new { Widget = partial }
    };
}

is this possible? Could somebody explain how?

note, I edited the question before posting the solution.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about partial-views