2

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.

Dmytro
  • 16,668
  • 27
  • 80
  • 130

2 Answers2

4

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...

Community
  • 1
  • 1
Sanja Melnichuk
  • 3,465
  • 3
  • 25
  • 46
2

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

Winson
  • 769
  • 6
  • 17