Here is a simple sample for how to add dynamic output in MVC using ViewBag:

In Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            int hour = DateTime.Now.Hour;
            ViewBag.Greeting = hour < 12 ? "Good morning" : "Good afternoon";
            return View();
        }
    }

In View:

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<div>
@ViewBag.Greeting, world
</div>

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2013 CodeEase.com Suffusion theme by Sayontan Sinha