RedirectToAction with parameter

后端 未结 14 1798
傲寒
傲寒 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:30

    It is also worth noting that you can pass through more than 1 parameter. id will be used to make up part of the URL and any others will be passed through as parameters after a ? in the url and will be UrlEncoded as default.

    e.g.

    return RedirectToAction("ACTION", "CONTROLLER", new {
               id = 99, otherParam = "Something", anotherParam = "OtherStuff" 
           });
    

    So the url would be:

        /CONTROLLER/ACTION/99?otherParam=Something&anotherParam=OtherStuff
    

    These can then be referenced by your controller:

    public ActionResult ACTION(string id, string otherParam, string anotherParam) {
       // Your code
              }
    

提交回复
热议问题