title: Ambiguous action methods
body: <p>I have a web page www.example.com which points to a HomeController index. When I run the website I get the HomeView.</p>
  
  <p>Now the requirement is when I type www.example.com/Japan I need to run a different view. </p>
  
  <p>What I did:</p>
  
  <pre><code> public ActionResult Index(string country)
      {
          ViewBag.Message = "my country=" + country;
  
          return View();
      }
  </code></pre>
  
  <p>But it gives me an error:</p>
  
  <blockquote>
    <p>The current request for action 'Index' on controller type 'HomeController' 
         is ambiguous between the following action methods:</p>
    
    <p>System.Web.Mvc.ActionResult Index() on type MvcApplication_2.Controllers.HomeController
         System.Web.Mvc.ActionResult Index(System.String) on type   MvcApplication_2.Controllers.HomeController</p>
  </blockquote>
  
  <p>What should I be doing to achieve this one?</p>
  
  <p>I do not want to use <a href="http://example.com/country/japan" rel="nofollow">http://example.com/country/japan</a>.</p>
  
  <p>I want to use <a href="http://example.com/japan" rel="nofollow">http://example.com/japan</a>.</p>
  
  <p>my code:
  RouteConfig.cs</p>
  
  <pre><code> namespace MvcApplication_2
   {
  public class RouteConfig
  {
      public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
          routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
          );
  
          routes.MapRoute(
          name: "ByCountry",
          url: "{country}",
          defaults: new { controller = "Home", action = "IndexByCountry" }
      );
  
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Homecontroller.cs</p>
  
  <pre><code> public class HomeController : Controller
   {
      [HttpGet]
      public ActionResult Index()
      {
          ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
  
          return View();
      }
  
  
      [ActionName("IndexByCountry")]
      public ActionResult Index(string country)
      {
          ViewBag.Message = "Japan man.";
  
          return View("Index");
      }
  
      public ActionResult About()
      {
          ViewBag.Message = "Your app description page.";
  
          return View();
      }
  
      public ActionResult Contact()
      {
          ViewBag.Message = "Your contact page.";
  
          return View();
      }
  }
  </code></pre>