I would like to convert this view
to string
and have the value in string
in my controller
The problem is that I would like it to execute an excerpt of script
that is in this view
The current method I have, just converts, without executing the script
that is in that view
Currently it looks like this:
public static string PartialViewToString(this Controller controller, string viewName, object model)
{
if (string.IsNullOrEmpty(viewName))
{
viewName = controller.ControllerContext.RouteData.GetRequiredString("action");
}
controller.ViewData.Model = model;
using (StringWriter stringWriter = new StringWriter())
{
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, stringWriter);
viewResult.View.Render(viewContext, stringWriter);
return stringWriter.GetStringBuilder().ToString();
}
}
In my controller I call:
var htmlString = helper.PartialViewToString(this,"NomeView",model);