如何在不添加area =“”的情况下指定默认区域到每个 ActionLink
我有一个基于 ASP.NET MVC2 RC2 构建的大型现有应用程序。
我的所有链接如下所示:htp//site/controller/action/id
我刚刚添加了一个名为:BigBird 的区域。
现在,当我在 BigBird 区域时,我的所有链接如下所示: htp://site/BigBird/controller/action/id
问题是这些控制器/操作都不存在于我的新区。所以我必须遍历我的应用程序中的所有操作链接并放置此路由值:area = string.empty
有什么办法可以解决这个问题吗?
I have a large existing application built on ASP.NET MVC2 RC2.
All of my links look like this: htp//site/controller/action/id
I just added an Area called: BigBird.
Now when I'm in the BigBird area, all of my links look like this: htp://site/BigBird/controller/action/id
Problem is that none of those controllers/actions exist in my new Area. So I have to go through all of my actionlinks all over my application and put this routevalue: area = string.empty
Is there any way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用标准 MVC 方法(除了可能覆盖它们来调用您自己的版本),但如果您使用
ActionLink
或其他通用方法,我不知道如何解决这个问题MvcFutures 库中提供的方法就可以。MvcFutures 方法调用
ExpressionHelper.GetRouteValuesFromExpression()
,它会在控制器上查找ActionLinkAreaAttribute
以确定区域。因此,您可以在主“区域”中装饰控制器,如下所示:应使用标准语法正确生成操作链接:
I don't know of away around it if you are using the standard MVC methods (other than maybe overriding them to call your own version), but if you are using the
ActionLink<TController>
or other generic methods provided in the MvcFutures lib then you can.The MvcFutures methods call
ExpressionHelper.GetRouteValuesFromExpression()
, which looks for anActionLinkAreaAttribute
on the controller to determine the area. So you can decorate your controllers in your main "area" as follows:The action links should be generated correctly using the standard syntax:
您可以做两件事之一。您可以将控制器/操作移动/复制到适当的区域,或者为新区域编写一些新控制器(这是我推荐的方法),或者您可以编写一个自定义路由,强制将新区域转移到根(我将其不推荐,因为它违背了拥有区域的全部目的):
You can do one of two things. You can either move/copy your controllers/actions into the proper area or write some new controllers for the new area (which is the approach I recommend), or you can write a custom route that forces the new area to the root (which I don't recommend, as it defeats the whole purpose of having areas):