我定义我首页查看像属性路由和RouteLink
<body>
<div>
<h1>Home</h1>
@Html.RouteLink("R1", "first", new { user="R1"})
@Html.RouteLink("R2", "second", new { company = "R2" })
</div>
</body>
和登录控制器像
public class LoginController : Controller
{
// GET: Login
[Route("{user}", Name = "first")]
public ActionResult Index(string user)
{
return View();
}
[Route("{company}", Name = "second")]
public ActionResult Index2(string company)
{
return View();
}
}
RouteConfig
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
我想象在主页R1和R2分别点击其路由正确的行为结果索引和索引2。
但其产生波纹错误
当前请求是采用以下的操作方法之间暧昧: System.Web.Mvc.ActionResult指数(System.String)上 类型MVCTest.Controllers.LoginController系统。 Web.Mvc.ActionResult 索引2(System.String)的类型MVCTest.Controllers.LoginController
我不知道为什么发生这种情况。
我知道你忙的人,有一些问题'routes'考虑在寻找我的答案来解决你所面临的问题。 – adricadar