Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear ViewBag message in MVC3

I am having a registration form. After successful registration I have to set ViewBag.Msg in controller and displayed it on view. This time all the fields are clear and only "You have registered successfully" message is there.

Now if I click on Submit then jquery validations are called and error messages like "Required field" are displayed.

But "successful" message is still there. How can I clear this message?

like image 230
user1120418 Avatar asked Dec 31 '25 13:12

user1120418


1 Answers

Use

TempData["mesage"]="Hello";

instead of

ViewBag.Message="Hello";

Because ViewBag maintain data on refresh also but TempData dispose after render once

like image 92
Amit Avatar answered Jan 02 '26 04:01

Amit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!