views:

71

answers:

3

Hi all

I have an ASP.NET MVC application and I'm trying to load the following html snippet from a Handler in another ASP.NET project, from one of my controllers to display in a View:

<br />
<div id="ctl00_divCommentary" class="commentary">
    <div id="ctl00_divCommentaryHeader">
        <span id="ctl00_lblCommentaryHeaderBold" class="commentaryHeader">blah</span>
        <span id="ctl00_lblCommentaryHeader">blah</span>
    </div>
    <div id="ctl00_divCommentaryText" class="commentaryText">blah blah blah</div>
</div>

The code that I'm using to get that html snippet is as follows:

public string GetCommentary()
{
    string commentary = "";

    Uri uri = new Uri("http://localhost/Handlers/CommentaryHandler.ashx");
    var doc = XDocument.Load(uri.ToString()); 

    commentary = doc.ToString();

    return commentary;
}

This is failing on the line

var doc = XDocument.Load(uri.ToString()); 

with the message "There are multiple root elements".

Is there a way to call that Handler and load the result into a string somehow?

Thanks

Dave

A: 

There are indeed more than one root elements (the <div> and the <br>). Either loose the <br> from the snippet or wrap all the snippet in another <div> to make it valid..

Gaby
A: 

This is what eventually worked:

<% Html.RenderAction("HtmlSource", "MyController"); %>

with the following method in the Controller:

public string HtmlSource()
{
    HtmlManager wm = GetHtmlManager(2, 6);

    return wm.Html;
}

The Html manager just reads the html from a file, same as text

DaveDev