【发布时间】:2015-04-23 07:36:08
【问题描述】:
我定义了我的主视图,比如
<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();
}
}
路由配置
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 上分别点击其路由到正确的操作结果 Index 和 Index2。
但它会产生以下错误
当前请求在以下操作方法之间存在歧义: System.Web.Mvc.ActionResult Index(System.String) 类型 MVCTest.Controllers.LoginController System.Web.Mvc.ActionResult MVCTest.Controllers.LoginController 类型上的 Index2(System.String)
我不知道为什么会这样。
【问题讨论】:
-
我知道您很忙,并且对
routes有一些问题,请考虑查看我的答案以解决您面临的问题。
标签: c# asp.net-mvc