2

I have some problems with creating two actions with the same name but 1 have a parameter and the other one not, I always get the this error:

ERROR:

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

These are my actions:

public IActionResult Skills(string skill)
{
   return View("SkillDetails");
}

public IActionResult Skills()
{
   return View("Skills");
}

These are my routes:

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "WithSkill",
        template: "Home/Skills/{skill}");

    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});
1
  • What other routes do you have, and is the route you have shown before all other routes Commented Apr 15, 2018 at 2:47

1 Answer 1

2

You can't differentiate by action parameters alone. Try renaming the action, or using an different HttpMethod if one is a Get and one is a Post. Or do something like this.

public IActionResult Skills(string skill)
{
   if(string.IsNullOrEmpty(skill)
      return View("Skill");
   return View("SkillDetails");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.