views:

13

answers:

1

I'm writing an ASP.NET MVC Html Helper which basically takes 2 HTML Helpers that return IHtmlStrings and combines them together and also returns them as an IHtmlString like so:

//this doesn't work
public static IHtmlString CompositeHelper(this HtmlHelper helper, string data)
{
    //GetOutput returns an IHtmlString
    var output1 = new Component1(data).GetOutput();
    var output2 = new Component2(data).GetOutput();

    return output1 + output2
}

Now I know this isn't going to work because IHtmlString is an interface with an implementation that is a complex type, but if I go

return output1.ToHtmlString() + output2.ToHtmlString()

I just get a normal string which gets HtmlEncoded when I return it from my HtmlHelper.

So my question is, how can I take the output form two IHtmlStrings and combine them into a single IHtmlString?

+1  A: 

Like this:

return new HtmlString(output1.ToString() + output2.ToString());
SLaks