xpg94
xpg94

Reputation: 513

mvc.net 4 view not showing ViewBag.Message

I created empty mvc.net 4 application in visual studio 2012. I added a "Service" controller:

public class ServiceController : Controller
    {
        //
        // GET: /Service/s

        public ActionResult Index()
        {
            ViewBag.text = "EEEE";
            return View();
        }

    }

and I right clicked on ActionResult, and added a view called "Index", and I put in this code:

@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>
<br>
<h2>@ViewBag.Message</h2>

And when I go to link "http://localhost:4376/Service/Index" , all the output I get is: "

Index

, and there is no "EEEE" text shown. What did I do wrong?

Upvotes: 5

Views: 10041

Answers (1)

user3559349
user3559349

Reputation:

ViewBag.text is not ViewBag.Message. Change the view code to

<h2>@ViewBag.text</h2>

or the controller code to

ViewBag.Message = "EEEE";

Upvotes: 7

Related Questions