0

ビュー/部分ビューをある場所(デフォルトの場所ではない)から取得してレンダリングする必要があります。カスタム 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 他にいい案があればよろしくお願いします。

4

0 に答える 0