.NET Fiddle

CSharp · Mvc

Model

using System;
using System.ComponentModel.DataAnnotations;

namespace HelloWorldMvcApp
{
	public class SampleViewModel
	{

	}
}

View

@model HelloWorldMvcApp.SampleViewModel
@{
	Layout = null;
}

<!DOCTYPE html>

<html lang="en">
	<head>
		
	</head>
	
	<body>
		Displayed text: <br/>
		@ViewBag.Test
	</body>
</html>

Controller

using System;
using System.Web.Mvc;
using System.Collections.Generic;

namespace HelloWorldMvcApp
{
	public class HomeController : Controller
	{
		[HttpGet]
		public ActionResult Index()
		{
			ViewBag.Test = "Test Message";
			// uncomment it and it will be cleared
			//ViewData.Clear();
			return View();
		}

	}
}
;