How to Render Partial View into an Object

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/29 12:23 UTC
Read the original article Hit count: 469

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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about partial-views