Domanda

I am trying to call action from another action by passing parameter values. Url is adding /category?id=1, but I was expecting /category/1. Don't know why it is sending with ?id=.

edit:

 return RedirectToAction(actionName: "Index", controllerName: "Category",
                routeValues: new {id=id});



    [HttpGet]
    [Route("Admin/Category/{langID:int=0}")]
    public ActionResult Index(int langId)
    {
       --
    }

after redirection url is Admin/Category?id=1

MapRoute

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

        routes.MapRoute(
            name: "AdminPages",
            url: "Admin/{controller}/{action}/{id}",
            defaults: new { controller = "Category", action = "Index", id = UrlParameter.Optional }
        );

        routes.MapRoute(
            name: "CategoryEdit",
            url:"Admin/{controller}/{action}/{id}",
            defaults: new { controller = "Category", action = "Index", id = UrlParameter.Optional });
È stato utile?

Soluzione

change your routeValues to routeValues: new { langId = id}; to match your action signature

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top