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:

viewbag-viewdata-and-tempdata

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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -