RedirectToAction with parameter

后端 未结 14 1799
傲寒
傲寒 2020-11-22 08:56

I have an action I call from an anchor thusly, Site/Controller/Action/ID where ID is an int.

Later on I need to redirect to th

14条回答
  •  悲&欢浪女
    2020-11-22 09:37

    Kurt's answer should be right, from my research, but when I tried it I had to do this to get it to actually work for me:

    return RedirectToAction( "Main", new RouteValueDictionary( 
        new { controller = controllerName, action = "Main", Id = Id } ) );
    

    If I didn't specify the controller and the action in the RouteValueDictionary it didn't work.

    Also when coded like this, the first parameter (Action) seems to be ignored. So if you just specify the controller in the Dict, and expect the first parameter to specify the Action, it does not work either.

    If you are coming along later, try Kurt's answer first, and if you still have issues try this one.

提交回复
热议问题