asp.net mvc5中的模糊匹配异常

时间:2016-01-04 05:39:07

标签: c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing

我有一个从另一个Controller派生的Controller,并且控制器都包含具有相同名称的方法。当我从Child Controller中的一个方法调用RedirectToAction时,我得到了" System.Reflection.AmbiguousMatchException:"

以下是代码段:

public class AccountController : Controller
 {
   [AllowAnonymous]
    public ActionResult Register()
    {
        return this.View();
    }
 }
public class UserController : AccountController
{
  [Route("User/")]
    [AllowAnonymous]
    public ActionResult Index(Guid eventId)
    {

       return RedirectToAction("Register","User", new { eventId = eventId });
    }


    [AllowAnonymous]
    public  ActionResult Register(Guid eventId)
    {
        return View("Register");
    }
 }

我在SubscribeController的Index方法中调用RedirectToActionFrom。

路线配置:

     public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");



        routes.MapRoute(
            name: "Subscribtion",
            url: "User/{eventId}/{action}/{id}",
            defaults: new { controller = "User", action = "Index", id = UrlParameter.Optional }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
        );
    }

0 个答案:

没有答案