AspNet MVC4 教授教养-14:Asp.Net MVC4 ViewBag等数据传输技术快速比较Demo
AspNet MVC4 教学-14:Asp.Net MVC4 ViewBag等数据传输技术快速比较Demo
2.遇上面对应的3个相应的View文件:
Index2.cshtml:
Index3.cshtml:
新建一个Basic类型的Project.
1.HomeCtroller.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcViewBagTest.Controllers { public class HomeController : Controller { //GET: /Home/ public ActionResult Index() { ViewBag.cs1 = "Index-ViewBag"; ViewData["cs2"] = "Index-ViewData"; TempData["cs"] = "Index-TempData"; Session["cs"] = "Index-Session"; return View(); } public ActionResult Index2() { return View(); } public ActionResult Index3() { return View(); } } }
2.遇上面对应的3个相应的View文件:
Index.cshtml:
@{ ViewBag.Title = "Index"; } <h2>Index</h2> <div>@ViewBag.cs1</div> <div>@ViewData["cs2"]</div> @*<div> @TempData["cs"]</div>*@ <div>@Session["cs"]</div> @Html.ActionLink("Index2", "Index2") @Html.ActionLink("Index3", "Index3")
Index2.cshtml:
@{ ViewBag.Title = "Index2"; } <h2>Index2</h2> <div>@ViewBag.cs1</div> <div>@ViewData["cs2"]</div> <div> @TempData["cs"]</div> <div> @Session["cs"]</div> @Html.ActionLink("Index3","Index3") @Html.ActionLink("Index","Index")
Index3.cshtml:
@{ ViewBag.Title = "Index3"; } <h2>Index3</h2> <div>@ViewBag.cs1</div> <div>@ViewData["cs2"]</div> <div> @TempData["cs"]</div> <div>@Session["cs"]</div> @Html.ActionLink("Index2","Index2") @Html.ActionLink("Index","Index")