Mitchel Smedts
Mitchel Smedts

Reputation: 21

ViewBag does not exist in current context in MVC 6 Beta 8

I am trying to get an MVC 6 beta 8 website up and running. The project contains Web controllers as well as api controllers. The api and web controllers are all working fine. But when using @ViewBag in the views gives the "ViewBag does not exist in the current context". The only thing in the entire solution that does not work are the views.

Anyone encountered a similar problem and is possible to point me into a certain direction or provide a solution?

Upvotes: 2

Views: 2181

Answers (3)

V.O.D
V.O.D

Reputation: 11

There was a similar problem in my app.

I deleted the relevant folder under the view section and added the view page from controller with add view way.

The problem was fixed.

Upvotes: 0

Abhay Shiro
Abhay Shiro

Reputation: 3627

I was facing the same problem.

I went to the project.json file in my solution and add this line of code

"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final" or "Microsoft.AspNetCore.Mvc": "1.0.0"

Sometimes we accidentally add wrong package name in the project.json file; always make sure you add the right thing! I prefer typing it out so I know exactly what I need to add. Quick Action (Ctrl + .) sometimes adds sub file reference (Not in all case; rarely).

I hope I was helpful.

Upvotes: 2

Martin Kearn
Martin Kearn

Reputation: 2317

It is called ViewData now.

To set in a controller

ViewData["Message"] = "fibble";

To read in your view

@ViewData["Message"]

Upvotes: 1

Related Questions