i have home controller. my home controller has two index method one with no parameter and one with parameter. it is like
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View("index");
}
public ActionResult Index(int a)
{
ViewData["Message"] = "Welcome to ASP.NET MVC! and Your Age is " + a;
return View();
}
i have define only two route entry in global.asax like
routes.MapRoute(
"Default1", // Route name
"{Home}/{ID}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"Default", // Route name
"{controller}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
I want that when i type url like http://localhost:7221 or http://localhost:7221/home then index() method with no param of home controller should fire and
when i type http://localhost:7221/home/77 then index(int a) method with param of home controller should fire. but i am getting error why i type two kind of url i specified. the error message is The current request for action 'Index' on controller type 'HomeController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index() on type BeginnerMVC.Controllers.HomeController System.Web.Mvc.ActionResult Index(Int32) on type BeginnerMVC.Controllers.HomeController
i am not being able to catch the error. what is wrong in my routing code. please help. thanks