问题描述
我必须建立在ASP.NET MVC2 RC2大量现有应用程序。
I have a large existing application built on ASP.NET MVC2 RC2.
我所有的链接看起来像这样:// HTP网站/控制器/操作/ ID
All of my links look like this: htp//site/controller/action/id
我刚刚添加称为区域: BigBird 。
I just added an Area called: BigBird.
现在,当我在BigBird地区来的,我所有的环节是这样的:HTP://网站/ BigBird /控制器/操作/ ID
Now when I'm in the BigBird area, all of my links look like this: htp://site/BigBird/controller/action/id
问题是我的新领域,没有这些控制器/存在的行动。所以,我有通过所有我actionlinks要走遍我的应用程序,并把这个routevalue:面积=的String.Empty
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?
推荐答案
我不知道它周围的路程,如果你使用的是标准的MVC的方法(可能比他们覆盖打电话给你自己的版本除外),但如果你用 ActionLink的< TController方式>
或MvcFutures LIB提供那么其他通用的方法,你可以
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.
该MvcFutures方法调用防爆pressionHelper.GetRouteValuesFromEx pression()
,其中寻找一个 ActionLinkAreaAttribute
在控制器上,以确定该地区。所以,你可以装饰你的控制器在主区域的方法如下:
The MvcFutures methods call ExpressionHelper.GetRouteValuesFromExpression()
, which looks for an ActionLinkAreaAttribute
on the controller to determine the area. So you can decorate your controllers in your main "area" as follows:
[ActionLinkArea("")]
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
动作链接应正确使用标准语法产生:
The action links should be generated correctly using the standard syntax:
<%= Html.ActionLink<HomeController>(c => c.Index(), "Home") %>
这篇关于如何指定默认的面积不增加面积=&QUOT;&QUOT;每ActionLink的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!