CSharp · Mvc
using System;
using System.ComponentModel.DataAnnotations;
namespace HelloWorldMvcApp
{
public class SampleViewModel
{
}
}
@model HelloWorldMvcApp.SampleViewModel
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
Displayed text: <br/>
@ViewBag.Test
</body>
</html>
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();
}
}
}