fearofawhackplanet
fearofawhackplanet

Reputation: 53396

ASP.NET MVC PartialView get html string

Is there a way to get the Html string from a PartialView inside the controller?

I have an odd scenario where I need to return some extra data along with the partial view to deal with error conditions.

What I'd like to do is something like:

 return Json( 
     new { 
         status = "OK", 
         content = PartialView("Orders", model).ToHTML() 
     });

I did find a similar question on here but none of the solutions were very clean and as that question is over 2 years old now I thought I'd see if there is any better way in MVC2.0.

Upvotes: 0

Views: 1525

Answers (1)

CGK
CGK

Reputation: 2662

You could use an Action along with RenderAction to accomplish that. More information in MSDN, here and in Phil Haack's blog.

Upvotes: 1

Related Questions