keep viewdata on RedirectToAction

后端 未结 5 1612
深忆病人
深忆病人 2021-02-01 01:40
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateUser([Bind(Exclude = \"Id\")] User user)
{
        ...
        db.SubmitChanges();
        ViewData[\"info\"] = \         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 02:26

    You could use the TempData controller property, but it has the disadvantage that it uses the session storage in the background. This means that you'll have extra work getting it to function on a web farm and you'll need to have sessions enabled in your application in the first place.

    An alternative is to use cookies if you only need to transport a short message. This does require proper encryption of the cookie. Not relying on the TempData property also allows you to set messages in a non MVC context, for example in a classic ASHX page.

    Take a look at FlashMessage which can save you some work implementing this yourself.

提交回复
热议问题