UrlMapping :: 忽略匹配块中的视图属性

发布于 2024-11-27 16:29:27 字数 386 浏览 0 评论 0原文

给定 URI /admin/article/index,为什么此 url 映射不起作用?

"/admin/$controller/$action?/$id?"{ 
        view = "/admin/index" // no dice, ignored 
        //action = "foo" // uncommented, this is picked up 
} 

我希望所有管理控制器默认使用管理视图(并且不必在每个控制器的每个操作中呈现视图)。对于“/account/$controller/...”和任何其他应使用通用视图的站点模块也是如此。

也许还有另一种方法可以实现这一目标,但假设 UrlMappings 是执行此操作的地方......

Given URI /admin/article/index, why would this url mapping not work?

"/admin/$controller/$action?/$id?"{ 
        view = "/admin/index" // no dice, ignored 
        //action = "foo" // uncommented, this is picked up 
} 

I'd like for all admin controllers to use the admin view by default (and not have to render the view in each action of each controller). Same goes for "/account/$controller/..." and any other site module that should use a common view.

Perhaps there's another way to achieve this, but assumed that UrlMappings is the place to do it...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫负雪 2024-12-04 16:29:27

看起来你正在尝试做一些与你所写的非常不同的事情。

您已经在基本 URL 映射中映射了 action,并且视图是根据 controller 自动选择的,因此您需要 定义不同映射那些没有控制器的视图,以及默认操作为 foo 的项目的另一个映射。不过,控制器上的默认操作是 index,因此通常不需要在不指定控制器的情况下提供默认操作。

我认为您总体上误解了 MVC 框架的工作原理。控制器不应该渲染任何内容,并且视图应该特定于控制器/操作。如果多个控制器正在渲染完全相同的视图,我愿意打赌要么控制器正在渲染 HTML,要么视图过于复杂。

您应该查看 SiteMesh 布局,它允许您创建默认模板结构,然后只需通过视图更改特定内容。

Looks like you are trying to do something very different than what you wrote.

You already have the action mapped in the base URL mapping, and the view is automatically selected based on the controller, so you need to define different mappings for those views that don't have a controller, and yet another mapping for items with a default action of foo. The default action on controllers is index, though, so there is usually no need to supply a default action without also specifying a controller.

I think you are, in general, misunderstanding how an MVC framework works. The controller should not be rendering anything, and the views should be specific to the controller/action. If multiple controllers are rendering the exact same view, I'd be willing to bet that either the controller is rendering HTML or the view is overly complicated.

You should look into Layouts with SiteMesh, which allows you to create default template structures, then just have the specific content change through views.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文