简体   繁体   English

强类型化Html.ActionLink <T> ()MVC Futures的辅助程序扩展在区域方面表现不佳

[英]Strongly typed Html.ActionLink<T>() helper extension from MVC Futures doesn't do well with areas

I noticed some odd behaviour when using the strongly typed HtmlHelper.ActionLink() extension method from ASP.NET MVC 2 Futures. 使用ASP.NET MVC 2 Futures的强类型HtmlHelper.ActionLink()扩展方法时,我注意到一些奇怪的行为。 When I use it to link to a controller in an area I have to use the following attribute on this controller 当我使用它链接到某个区域中的控制器时,必须在该控制器上使用以下属性

[ActionLinkArea("SomeArea")]

It links properly to the actions of the controller located in SomeArea from the default area. 它从默认区域正确链接到位于SomeArea中的控制器的动作。 The problem is when I want to link back to a Controller action located in the default area from within SomeArea. 问题是当我想从SomeArea内链接回位于默认区域的Controller动作时。 The link appears with "/SomeArea/" prefix. 该链接显示为“ / SomeArea /”前缀。 The workaround I use is: 我使用的解决方法是:

[ActionLinkArea("")]

on the controller on all controllers that are located in the default area (using inheritance). 在控制器上位于默认区域中的所有控制器上(使用继承)。

This seems odd because in my opinion that should be the default behavior of this method. 这似乎很奇怪,因为我认为这应该是此方法的默认行为。 Using .NET Reflector on this extension method I noticed that the error lies here: 在此扩展方法上使用.NET Reflector时,我注意到该错误位于此处:

return helper.RouteLink(linkText, routeValuesFromExpression, new RouteValueDictionary(htmlAttributes));

So it's actually the default behaviour of the HtmlHelper . 因此,这实际上是HtmlHelper的默认行为。

Known issue in MVC 2 Futures - same underlying cause as http://forums.asp.net/p/1535698/3732346.aspx . MVC 2期货中的已知问题-与http://forums.asp.net/p/1535698/3732346.aspx相同的根本原因。

From our internal database, if you wanted to patch the file and recompile MVC Futures yourself: 在我们的内部数据库中,如果您想修补文件并自己重新编译MVC Futures:

The bug is in LinkBuilder.cs, line 21. The method call GetVirtualPath() should be GetVirtualPathForArea(). 该错误在LinkBuilder.cs的第21行中。方法调用GetVirtualPath()应为GetVirtualPathForArea()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM