i create two action method with different name in home controller
public ActionResult Default()
{
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();
}
and my routing code look like
routes.MapRoute(
"Default1", // Route name
"{Home}/{ID}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"Default2", // Route name
"{Home}", // URL with parameters
new { controller = "Home", action = "Default" }
);
routes.MapRoute(
"Default", // Route name
"{controller}", // URL with parameters
new { controller = "Home", action = "Default" }
);
but still getting problem
when i type url like http://localhost:7221 then home is coming and Default() method invoking but if i type url like
http://localhost:7221/Home then getting error. to handle this situation i define route like
routes.MapRoute( "Default2", // Route name "{Home}", // URL with parameters new { controller = "Home", action = "Default" } );
but it is not working.......can u tell me why.
if i type url like http://localhost:7221/Home/88 then Index(int a) method should be called but getting error. why
i want that when i type url http://localhost:7221 or http://localhost:7221/Home then Default() should be called and when i will type
http://localhost:7221/Home/88 then Index(int a) should be invoked. what is wrong in my route. how can i rectify it. if possible rectify my route code. thanks