I've created a basecontroller class based of a blog post I found to return a partial view as a result in a ContentResult type action in my controller. The code for that is here:
protected string RenderPartialViewToString(string viewName, object model)
{
if (string.IsNullOrEmpty(viewName))
viewName = ControllerContext.RouteData.GetRequiredString("action");
ViewData.Model = model;
using (StringWriter sw = new StringWriter())
{
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
}
I use the following to return that:
return Content(RenderPartialViewToString("LocationStaffSearch", lcps));
So now I need to return a partial that's a shared view. I can't seem to figure out how to pass the name so it finds the partial. If I just type in the name it renders out a blank string. If I put in Share/LocationStaffSearch it returns an error saying the view is null.