Success message from Controller to View

前端 未结 6 1422
情歌与酒
情歌与酒 2020-12-30 05:05

The goal

I want to display in my view some message when some user is added.

The problem

When something goes wrong in our model, there is a method

6条回答
  •  既然无缘
    2020-12-30 05:28

    A good solution for this is the TempData collection. Its values are cleared at the end of the request which makes it ideal for one time messages like informing the user that something was successful.

    Controller

    TempData["Message"] = "Operation successful!";
    

    View

    @TempData["Message"]
    

    And yes, this is still currently the best approach.

提交回复
热议问题