c0D3l0g1c
c0D3l0g1c

Reputation: 3164

.NET MVC Render Website to View

I need to render a remote website into an iframe. Which is simple enough to do. Problem i'm faced with is automatically adjusting iframe height to it's content, due to cross domain security issues.

To circumvent this, i was thinking of doing something like this:

Get server to request url and return response to client. Get client to render the response in a view.

Is this possible? Some advice on how to achieve this would be appreciated.

Upvotes: 0

Views: 1301

Answers (1)

Ajay Kelkar
Ajay Kelkar

Reputation: 4621

You can bring url content from server and pass it in partial view and use it anywhere.

Lets say your action name is GetRemoteContent

ActionResult GetRemoteContent(string url)
{
WebClient webpage = new WebClient();
string html=  webpage.DownloadString(url);
return View("RemoteContent",html);
}

RemoteContent.cshtml partial view

@model string 

<div> 
   @Html.Raw(model)
</div> 

Usage :

 @{ Html.RenderAction("MyController","GetRemoteContent",new {url="http://somewebsite.com"}) }

Upvotes: 3

Related Questions