I’m creating this contact form which is pretty much what you can find on the documentation:
http://our.umbraco.org/documentation/Reference/Mvc/forms
The problem is that on my action I’m adding some data to the ViewData collection but I’m unable to get in on the view.
Here is the action:
public ActionResult ProcessForm(ContactFormModel model)
{
if (!ModelState.IsValid) {
// do something here
return CurrentUmbracoPage();
}
// process form
// set success flag
ViewData("SuccessMessage") = "We will be contacting you soon..";
return RedirectToCurrentUmbracoPage();
}
Here is the view:
<h1>@ViewData("SuccessMessage")</h1>
It will return this error:
Compilation Error, Error Message: CS0103: The name ‘ViewData’ does not exist in the current context
ViewData should be set and called using
ViewData["some key"], notViewData("some key"). This is because ViewData is essentially a dictionary and not a method on theControllerBaseclass.See here for a good explanation of its use.