简体   繁体   中英

Attribute Routing - Strongly Typed Action Links

I am currently using the standard routing config and T4MVC for my ActionLinks like so:

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.

Is there a way to get T4MVC to work with attribute routing? 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. This will make sure that you have everything set up correctly, like calling MapMvcAttributeRoutes in the correct place (which can be tricky for areas ).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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