Asp – The incoming request does not match any route in My sample mvc application

asp.netasp.net-mvc

Hai guys,
I started a new asp.net mvc application and i followed the steps given in
http://www.packtpub.com/article/your-first-asp.net-mvc-application

when i press F5 i got the error "The incoming request does not match any route"…
Any suggestions ….

Update:

 public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "EmployeeShow",                    // Route name
            "Employee/{firstname}",            // URL with parameters
             new
             {                             // Parameter defaults
                 controller = "EmployeeController",
                 action = "Show",
                 firstname = ""
             }
        );

    }

My controller

public class EmployeeController : Controller
{
    //
    // GET: /Employee/

    public ActionResult Show(string firstname)
    {
        if (string.IsNullOrEmpty(firstname))
        {
            ViewData["ErrorMessage"] = "No firstname provided!";
        }
        else
        {
            Employee employee = new Employee
            {
                FirstName = firstname,
                LastName = "Example",
                Email = firstname + "@example.com"
            };

            ViewData["FirstName"] = employee.FirstName;
            ViewData["LastName"] = employee.LastName;
            ViewData["Email"] = employee.Email;
        }

        return View();
    }

}

Best Answer

You have no "Default" route in your RegisterRoutes method and your first request WILL NOT match the route you do have as you have specifically specified the controller request .... this is normal and expected behaviour based on your configuration:

public static void RegisterRoutes(RouteCollection routes) {
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");        
     routes.MapRoute("EmployeeShow",              
                   "{controller}/{firstname}",  // change this line from "Employee" to {controller}
                    new {controller = "Employee", action = "Show", firstname = "" });    
 }