result:

@model HelloWorld.Models.HomeModel
@{
    ViewBag.Title = "Index";
}

<!--<h2>@ViewData["message1"]</h2>
<br />
<h2>@ViewBag.Message</h2>-->

<h2>@Model.Message</h2>

----------------------------------------------------------------------------------

1) ViewData

        public ActionResult Index(string lang)
        {
            ViewData["message1"] = "oh~~~ Yeah!!.";

            return View();
        }

2) ViewBeg 

        public ActionResult Index(string lang)
        {
            ViewBag.Message = "oh~~~ Yeah!!2.";

            return View();
        }

3) Model 

        public ActionResult Index(string lang)
        {

            HomeModel model = new HomeModel();
            if (lang == "Chinese")
            {
                model.Message = "ha lo!!";
            }
            else
            {
                model.Message = "Hello!!!!!!!!!!!!";
            }

            return View(model);
        }

 4) TempData --------------One Time Deal, you can get from TempData only after you hit submit. when you try to do refresch, the message will gone.

        public ActionResult Index(string lang)
        {
            if (ModelState.IsValid)

            {

                 TempData["message"] = "the transaction is processed!";

                 return RedirectToAction("Index");

             }

            return View();
        }

 

arrow
arrow
    文章標籤
    MVC3 ViewData ViewBeg 傳遞
    全站熱搜
    創作者介紹
    創作者 chilliwack425 的頭像
    chilliwack425

    無聊的部落格

    chilliwack425 發表在 痞客邦 留言(0) 人氣()