Unable to use ViewBag in Views and Controllers
I just added some MVC Views and Controllers to my Sitefinity Web Application project which uses the ViewBag element, but when I attempt to access any of these pages, I receive the following error message:
Compiler Error Message: CS0103: The name 'ViewBag' does not exist in the current context
How do I get the ViewBag element to render correctly within my Sitefinity MVC Views and Controllers?
Please advise.
Hi,
Define ViewBag value in the controller method action
public
ActionResult Index()
var model =
new
ViewBagTestModel();
if
(
string
.IsNullOrEmpty(
this
.Message))
model.Message =
"Hello, World!"
;
ViewBag.Test =
"This is text form Viewbag"
;
and in the view call ViewBag with its key for access in my case its "Test";
@
@ViewBag.Test