asp.net - ViewBag.result is null in the View after setting in HttpPost -
i have httppost method call submit database add transcation. if success, set viewbag.result = "successfully added"
var response = updatedatabase(command); if (response.success) viewbag.result = "successfully added"; redirecttoactoin("submitapplication"); in view,
if (!string.isnullorempty(@viewbag.result)) { <p> @viewbag.result</p> } i placed breakpoint , viewbag.result null.
i not sure why viewbag.result null. appreciated. thanks.
you should use tempdata["result"] data can used after redirect.
as msdn states tempdata:
represents set of data persists 1 request next.
also, see more information usage here:
sample usage:
tempdata["results"] = "successfully added";
and in submitapplication method:
var message = (string)tempdata["results"];
always check nulls etc have not done in example.
Comments
Post a Comment