1

I have this method who call 2 others methods but i've an error when a execute that code.

public ActionResult CreateOrder(string action, string type)
    {
        /*Some Code*/
        if(MyObject.isOk){
            return RedirectToAction("EditOrder", new { code = ErrorCode, libelle = Description });

        }else{
            return RedirectToAction("EditOrder", new { nordre = NoOrdre });
        }
    }

public ActionResult EditOrder(string nordre)
    {

    }

[ActionName("EditOrder")]
public ActionResult EditOrderError(string code, string libelle)
{

    }

But i get an 404 because the script try to find the "EditOrderError" view.

Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
Portekoi
  • 1,087
  • 2
  • 22
  • 44

2 Answers2

2

ASP.NET MVC doesn't allow you to overload controller actions unless they handle different HTTP verbs.

Assuming you're using C# 4, one possible workaround, albeit not a pretty one, is to use optional parameters on a single controller action:

public ActionResult EditOrder(string nordre = null, string code = null, string libelle = null)
{
    if (nordre != null)
    {
        // ...
    }
    else if (code != null && libelle != null)
    {
        // ...
    }
    else
    {
        return new EmptyResult();
    }
}
Community
  • 1
  • 1
Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
1

You cannot overload controller actions using the same HTTP Method/Verb (GET/POST/ etc)

I would only use ActionNameAttribute if I need the controller action to have characters that .NET doesn't allow in an identifier. Like using dashes (/controller/create-user). Like this one..

Community
  • 1
  • 1
aiapatag
  • 3,355
  • 20
  • 24