英文书也没有那么难,跟着例子做,挺有意思的

控制器

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

namespace mvcDemo.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            int hour = DateTime.Now.Hour;
            ViewBag.Greeting = hour < 12 ? "Good Morning" : "Goods Afternoon";
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Contact()
        {
            return View();
        }
    }
}

视图层

<!DOCTYPE html>
@{
    Layout = null;
}

<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>首页</title>
    <link rel="stylesheet" href="">
</head>
<body>
    <div>@ViewBag.Greeting World!</div>
</body>
</html>

posted @ 2017-05-19 17:40  TBHacker  阅读(182)  评论(0编辑  收藏  举报