Failure of partial in extension method fails

I create a tabcontainer that displays information from partials. The code I created looks like this:

//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 renderpartial writes directly to the output stream. I also cannot show a partial row. to add it to the stringbuilder object.

Any suggestions?

+3
source share
1 answer

use

m_helper.Partial(tab.PartialName);

This will return an MvcHtmlString .

+5
source

Source: https://habr.com/ru/post/1753324/


All Articles