MVC 5 Routing Attribute

后端 未结 4 1321
梦如初夏
梦如初夏 2020-12-19 00:37

I have the Home Controller and my Action name is Index. In My route config the routes like below.

routes.MapRoute(
    \"Default\",   // Route name
    \"{c         


        
4条回答
  •  星月不相逢
    2020-12-19 01:07

    Please check here for information on routing: http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/asp-net-mvc-routing-overview-cs

    Most likely, default routing should be something like below:

    routes.MapRoute(
                    "Default",                                              // Route name
                    "{controller}/{action}/{id}",                           // URL with parameters
                    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
                );
    

    Also, looks like the Index Action Method is missing a parameter, see below:

    public ActionResult Index(string id)
            {
                return View();
            }
    

    Try placing string id in your Index method.

提交回复
热议问题