开发者

Is there any way to combine the output of two IHtmlStrings into a single IHtmlString instance?

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 th开发者_JAVA百科e output form two IHtmlStrings and combine them into a single IHtmlString?


Like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜