开发者

Can I populate a ContentPlaceHolder in a master page from within a Razor Partial View?

开发者 https://www.devze.com 2023-04-13 00:33 出处:网络
I\'m using the typical built in view engine in mvc3 (is there a proper name for it?) for views and master pages and it\'s including a Razor partial view on the .aspx page.In the masterpage, there is a

I'm using the typical built in view engine in mvc3 (is there a proper name for it?) for views and master pages and it's including a Razor partial view on the .aspx page. In the masterpage, there is a ContentPlaceHolder with an ID of "ScriptContent".

I want to be able to fill that ContentPlaceHolder from within the Razor partial view but I don't think this is possible. Does anyone know if it is possible and how I would go about doing that?

I already tried rendering开发者_开发技巧 it in the partial like so, but that didn't work.

@section ScriptContent {
    ... content ...
}


It would be very difficult, so much so that I'd recommend finding another way :(. I wish it was easier, but these are the complexities of integrating a new view engine into an existing legacy system.

To give you a head start if you really want to try it: You'd probably need to create a custom base class inheriting from WebViewPage for your Razor content pages, override some of the methods (honestly I'm not too familiar with that aspect so you'd need to debug to follow the pipeline) so that instead of treating the Layout property as the path to a Layout page, you treat it as a Master page. Then you'd need to instantiate the master page and somehow convert the Sections (which were transformed into calls to DefineSection by the Razor parser, and should be stored in a Dictionary somewhere on the base class) in to Content controls and stuff them in the Master Page.

If I haven't boggled your mind by this point, you may just be able to pull this off, but to be honest, I'd avoid it.

P.S. We refer to the older view engine as "ASPX", based on its file extension ;).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号