user1250264 February 2016
ViewBag.result is null in the View after setting in HttpPost
I have a HttpPost method which I call a submit to database add transcation. If success, I set my viewbag.result = "successfully added"
var response = UpdateDatabase(command);
viewbag.result = "successfully added";
In the view,
I placed a breakpoint and the viewbag.result is null.
I am not sure why the viewbag.result is null. Any help is appreciated.
Ric February 2016
You should use
TempData["Result"] so that your data can be used after your redirect.
As MSDN states for
Represents a set of data that persists only from one request to the next.
Also, see more information about usage here:
TempData["Results"] = "successfully added";
And in your
var message = (string)TempData["Results"];
Always check for nulls etc which I have not done in this example.
Asked in February 2016
Viewed 2,559 times
Answered 1 times
Leave an answer
Quote of the day: live life