简体   繁体   English

属性路由-强类型操作链接

[英]Attribute Routing - Strongly Typed Action Links

I am currently using the standard routing config and T4MVC for my ActionLinks like so: 我目前正在为我的ActionLink使用标准路由配置和T4MVC,如下所示:

routes.MapRoute("Default",
                "{controller}/{action}",
                new { controller = "Home", action = "Index", id = "" },
                new[] { "HM.Web.Controllers.Home" }
                );

@Html.ActionLink("Login", MVC.Login.Index())

But now I would like to move to attribute routing in MVC 5, from initial tests it doesn't look as if T4MVC will pickup my attribute routes and falls back to using the default route. 但是,现在我想从最初的测试转到MVC 5中的属性路由,看起来T4MVC不会选择我的属性路由并回退到使用默认路由。

Is there a way to get T4MVC to work with attribute routing? 有没有办法使T4MVC与属性路由一起使用? and if not is there an alternative to get strongly typed action link? 如果没有,还有没有其他方法可以获取强类型的动作链接?

This should work. 这应该工作。 The first thing you should check is that you are getting the right link if you don't use T4MVC. 您应该检查的第一件事是,如果使用T4MVC,您将获得正确的链接。 This will make sure that you have everything set up correctly, like calling MapMvcAttributeRoutes in the correct place (which can be tricky for areas ). 这将确保您正确设置了所有内容,例如在正确的位置调用MapMvcAttributeRoutes (这对于area可能是棘手 )。

If that works without T4MVC, but the equivalent T4MVC call doesn't, then we have a strange situation to investigate, but let's wait till we get there. 如果在没有T4MVC的情况下仍然有效,但是等效的T4MVC调用不起作用,那么我们有一个奇怪的情况要研究,但是让我们等到到达那里。

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

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