Asp.net mvc 如何在MVC中使用自定义ViewEnging获取视图并进行渲染?

Asp.net mvc 如何在MVC中使用自定义ViewEnging获取视图并进行渲染?,asp.net-mvc,model-view-controller,asp.net-mvc-2,c#-4.0,actionresult,Asp.net Mvc,Model View Controller,Asp.net Mvc 2,C# 4.0,Actionresult,我需要从某个位置(不是默认位置)获取view/partialview并进行渲染。 我想创建自定义视图引擎。我的想法如下: 1-返回Plugin作为在构造函数中获取pluginName的操作结果 public class PluginController : Controller { [HttpPost] public ActionResult LoadPlugin(string pluginName) { retur

我需要从某个位置(不是默认位置)获取view/partialview并进行渲染。 我想创建自定义视图引擎。我的想法如下:

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-在ExecuteSult中,我将创建
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"
            };
        }
    }
Sow,我怎样才能获得视图并渲染它


另外,如果您有任何其他建议,我将很高兴。

您能在某个地方构建位置地址,然后将其传递给默认视图引擎吗?例如,
返回视图(“~/PluginsArchive/SomeName.ascx”,model)
其中“~/PluginsArchive/SomeName.ascx”是在其他地方构造的。我想将它放在插件结果(executesult)中,这样控制器将是“干净的”@Charlino,但是SomeName.ascx可以位于PluginsArchive中的某个目录中,为了编写搜索逻辑,我希望视图引擎能够执行此操作,因为它按照it@theateist,返回视图(“~/PluginsArchive/SomeName.ascx”)与返回新插件(“~/PluginsArchive/SomeName.ascx”)有何不同?我不明白你在这里想要实现什么。这些视图是否位于应用程序的虚拟目录之外?