Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render partial in an extension method fails

I'm creating a tabcontainer that shows information from partials. The code that i've created is as follows:

//Entering extension method, m_helper is of type HtmlHelper
foreach (var tab in m_tabList)
{
    sb.AppendLine("<div class='tabContent'>"); 
    m_helper.RenderPartial(tab.PartialName);
    sb.AppendLine("</div>");    
}
//Returning sb.ToString to the caller method

This will not work because the renderpartial writes directly to the output stream. I cannot render the partial to a string either. to add it to the stringbuilder object.

Any suggestions?

like image 350
MichaelD Avatar asked Apr 26 '26 02:04

MichaelD


1 Answers

use

m_helper.Partial(tab.PartialName);

This will return MvcHtmlString.

like image 58
Amitabh Avatar answered Apr 27 '26 14:04

Amitabh