Calling the function
string InvoiceHtml = myFunction.RenderPartialViewToString("PartialInvoiceCustomer", ToInvoice); // ToInvoice is a model, you can pass parameters if needed
Function to generate HTML
public static string RenderPartialViewToString(string viewName, object model)
{
...