RedirectToAction with parameter

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

    MVC 4 example...

    Note that you do not always have to pass parameter named ID

    var message = model.UserName + " - thanks for taking yourtime to register on our glorious site. ";
    return RedirectToAction("ThankYou", "Account", new { whatever = message });
    

    And,

    public ActionResult ThankYou(string whatever) {
            ViewBag.message = whatever;
            return View();
    } 
    

    Of course you can assign string to model fields instead of using ViewBag if that is your preference.

提交回复
热议问题