开发者

MVC How to affect a Layout page from a View Page

开发者 https://www.devze.com 2023-03-20 18:00 出处:网络
I\'m about to describe a specific problem that we have on our MVC project but one which is similar to other problems that follow the same pattern. I mention this because i want to think about the solu

I'm about to describe a specific problem that we have on our MVC project but one which is similar to other problems that follow the same pattern. I mention this because i want to think about the solution in generic terms that could be applied to many situations.

In our MVC2 application (using Spark) we have a master layout page which contains a child action controller link to render some page metadata. This page meta data varies depending on the actual view being being displayed. We therefore need to pass some data from the View or the Views controller to the child action on the layout page. Sometimes the meta tags only need to know the current Views name to show the correct metatags, other pages need to pass things such as product IDs.

Now we know we can create out own base controller that the View Controler would inherit from, and make the base call a abstract method to get the data from the View Controller; o开发者_运维知识库r have the View Controller put data into the ViewData basket that the Layout could read and pass into the child action controller, but both these approaches seem messy.

Is there another way to do this that the framework can help us with? I'd like it if you could think in general terms about the problem of affecting a layout page from a View/ViewController as i have other situations where this kind of situation is a problem.

Thanks in advance

0

精彩评论

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

关注公众号