MVC 2.0 - 基于具有共享控件的 URL 的不同视图
我有 2 个母版页。一个旨在显示在普通的独立网站中。另一个是作为 Iframe 在外部站点中使用。
我希望能够在 http://example.com/home/index 显示正常页面iframed 版本 http://example.com/framed/home/index
我想要将回发到一个控制器的控件,这样我就不必重复逻辑,因此它们必须在普通版本和 iframed 版本中都可用。
我的问题是,当我尝试使用区域时,我无法让它们与默认 url 一起正常工作。另外,我还增加了结构图的复杂性。当我尝试点击 /area/controller/action 时,我得到
IControllerFactory 'MySite.Web.Code.IoC.StructureMapControllerFactory' 没有返回控制器 命名为“我的区域”。
有谁知道如何使这种设置工作?实际上,我所做的只是尝试显示一组视图(如果它具有 /Framed/controller/action)和另一组视图(如果它没有 /framed)。我认为区域是一条出路,但也许不是。
I have 2 master pages. One is intended to be shown in a normal standalone website. The other is to be used in external sites as an Iframe.
I want to be able to show the normal page at http://example.com/home/index and the iframed version at http://example.com/framed/home/index
I want to have controls that will postback to one controller so I don't have to duplicate logic, so they must be available in both the normal and iframed versions.
My problem is that when I try and use areas, I just can't get them to work right with the default url. Also, I have the added complication of structuremap. When I try and hit /area/controller/action, I get
The IControllerFactory
'MySite.Web.Code.IoC.StructureMapControllerFactory'
did not return a controller for the
name 'MyArea'.
Does anyone know how to make this kind of setup work? Really all I'm doing is trying to show one set of views if it has /Framed/controller/action and another set if it does not have /framed. I thought areas were the way to go, but maybe not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们所有的控制器都实现相同的基类,并且我们使用以下重写来执行您所描述的操作:
我们所有的 AreaRegistrations 使用以下方法来注册其区域:
然后您在第一个代码块中看到的 PortalRequestManager 进行解析URL 以查看它是否使用“/P”或“/F”来确定要使用哪个 MvcMasterPath。
我们使用 Ninject 的控制器工厂,它对此设置没有问题,所以我无法真正谈论您在 StructureMap 方面的问题。
All of our controllers implement the same base class, and we use the following override to do what you're describing:
All of our AreaRegistrations use the following method to register their areas:
And then the PortalRequestManager that you saw in the first code block parses the URL to see if it uses "/P" or "/F" to determine which MvcMasterPath to use.
We use Ninject's controller factory, which has no problem with this setup, so I can't really speak to your problems with StructureMap.