我正在尝试使用这个问题的公认答案。
看来这正是我正在寻找的,但我有一个问题。我不知道该怎么称呼它。这是我到目前为止所拥有的:
首先,我从我提到的解决方案中复制代码:
public string ToHtml(string viewToRender, ViewDataDictionary viewData, ControllerContext controllerContext)
{
var result = ViewEngines.Engines.FindView(controllerContext, viewToRender, null);
StringWriter output;
using (output = new StringWriter())
{
var viewContext = new ViewContext(controllerContext, result.View, viewData, controllerContext.Controller.TempData, output);
result.View.Render(viewContext, output);
result.ViewEngine.ReleaseView(controllerContext, result.View);
}
return output.ToString();
}
这就是我所拥有的:
string viewToRender = "...";
int Data1 = ...;
int Data2 = ...;
System.Web.Mvc.ViewDataDictionary viewData = new System.Web.Mvc.ViewDataDictionary();
viewData.Add("Data1",Data1);
viewData.Add("Data2",Data2);
string html = ToHtml(viewToRender, viewData, ?????)//Here is my problem.
我应该在 controllerContext 参数中传递什么?