Zu den Aktionen mit denselben Namen, aber unterschiedlichen Parametern verzweigen

Habe ich diesen Satz von Routen:

        routes.MapRoute(
            "IssueType",
            "issue/{type}",
            new { controller = "Issue", action = "Index" }
        );

        routes.MapRoute(
            "Default", //Route name
            "{controller}/{action}/{id}", //URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } //Parameter defaults
        );

Hier ist die controller-Klasse:

public class IssueController : Controller
{
    public ActionResult Index()
    {
        //todo: redirect to concrete type
        return View();
    }

    public ActionResult Index(string type)
    {
        return View();
    }
}

warum, wenn ich bitte http://host/issue bekomme ich The current request for action 'Index' on controller type 'IssueController' is ambiguous between the following action methods:

Ich erwarte, dass zunächst eine Methode handeln sollte, wenn es keine Parameter, und das zweite, wenn einige parameter angegeben.

wo habe ich Fehler gemacht?

UPD: mögliche Duplikate: Können Sie überlastung controller-Methoden in ASP.NET MVC?

UPD 2: aufgrund der obigen link - es gibt keine rechtliche Möglichkeit, um action-überladen, ist es?

UPD 3: Action-Methoden nicht überladen werden, basierend auf Parametern, (c) http://msdn.microsoft.com/en-us/library/system.web.mvc.controller%28VS.100%29.aspx

InformationsquelleAutor der Frage zerkms | 2010-04-12

Schreibe einen Kommentar