我需要从某个位置(不是默认位置)获取视图/部分视图并进行渲染。我想创建自定义 ViewEngine。我想到了以下几点:
1 -Plugin
作为在构造函数中采用 pluginName 的操作结果返回
public class PluginController : Controller
{
[HttpPost]
public ActionResult LoadPlugin(string pluginName)
{
return new Plugin(pluginName);
}
}
public class Plugin : ActionResult
{
private readonly string PluginName;
public PEditorPlugin(string pluginName)
{
this.PluginName = pluginName;
}
public override void ExecuteResult(ControllerContext context)
{
var engine = new MyViewEngine();
string viewContent = // Here I need some how to take the view with partialName and to render it
context.RequestContext.HttpContext.Response.Write(content);
}
}
2 - 在 ExecuteResult 我将创建实例MyViewEngine
并以某种方式获取视图并渲染它。但是怎么做我不知道!
public class MyViewEngine : WebFormViewEngine
{
public override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
{
return new WebFormView(partialPath, null);
}
public MyViewEngine ()
{
// create our partial views and common shared locations
PartialViewLocationFormats = new[] {
"~/PluginsArchive/{0}.ascx"
};
}
}
母猪,我如何获取视图并渲染它?
PS如果您有任何其他建议,我会很高兴。