How to render partial view to string?

How to call Html.Partial() method from controller or some other method in external class library?

I need something like:

string someView = "SomeView";
object someModel = new SomeModel();    
HtmlHelper helper = new HtmlHelper();    
string html = helper.Partial(someView, someModel).ToString();

I need to get html string which this method returns.

Answers


If you want to render partial view to string you can use this link: Render a view as a string

But i think you doing something wrong...


you need to use WebClient for download the html page, something like that:

string viewUrl = Url.RouteUrl(new { Controller = "Pages", Action = "Index" });

WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
string result = client.DownloadString(new Uri(viewUrl ));

then you will get the page's html


Need Your Help

Extending System.Convert

c# .net .net-4.0 types type-conversion

System.Convert has a really useful utility for converting datatypes from one type to another. In my project, I have many custom types. I want to convert command line arguments to these custom typ...

AngularJS Stopped Working

angularjs html5

I'm working on a test project with angular, but sudently it stopped working!