keep viewdata on RedirectToAction

Posted by Thomas Stock on Stack Overflow See other posts from Stack Overflow or by Thomas Stock
Published on 2009-08-04T08:37:05Z Indexed on 2010/06/18 0:13 UTC
Read the original article Hit count: 303

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateUser([Bind(Exclude = "Id")] User user)
{
        ...
        db.SubmitChanges();
        ViewData["info"] = "The account has been created.";
        return RedirectToAction("Index", "Admin");
}

This doesnt keep the "info" text in the viewdata after the redirectToAction. How would I get around this issue in the most elegant way?

My current idea is to put the stuff from the Index controlleraction in a [NonAction] and call that method from both the Index action and in the CreateUser action, but I have a feeling there must be a better way.

Thanks.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about best-practices