Hi guys, I want to know how do I pass a value from controller to view, I´m trying to use ViewBag, but the value is not presented. I got the following method that creates a new node using a the values of a contact form:
public ActionResult HandleFormPost(Contact contact)
{
ViewBag.message= "A sua sugestão foi enviada com sucesso";
var message= Services.ContentService.CreateContent(contact.Name+ " - " + DateTime.Now, CurrentPage.Id, "ContactForm");
message.SetValue("name", contact.Name);
message.SetValue("email", contacto.Email);
message.SetValue("message", contacto.Message);
Services.ContentService.SaveAndPublishWithStatus(message);
return RedirectToCurrentUmbracoPage();}
And the I use the ViewBag in the page
@ViewBag.message
But I got no results, anyone knows how to solve this??
Passing values from a controller to view
Hi guys, I want to know how do I pass a value from controller to view, I´m trying to use ViewBag, but the value is not presented. I got the following method that creates a new node using a the values of a contact form:
And the I use the ViewBag in the page
But I got no results, anyone knows how to solve this??
Best Regards
Hi Vanilson. When you do a redirect the value of your ViewBag gets lost. Instead, use TempData.
TempData["Message"]
http://www.dotnet-tricks.com/Tutorial/mvc/9KHW190712-ViewData-vs-ViewBag-vs-TempData-vs-Session.html
ViewBag: It’s life lies only during the current request.
TempData: TempData is used to pass data from current request to subsequent request (means redirecting from one page to another).
Hope this was helpful!
All the best / Dennis
Hi Dennis, thank you for the reply, it works.
Best Regards
Awsome Vanilson! Glad I could help! Have a great day!! :)
is working on a reply...