ASPNET MVC3技术要点(10)
发布时间:2021-06-06
发布时间:2021-06-06
ASPNET MVC3技术要点
3.2.1.3 返回指定路径及名的视图 public ViewResult Index() {
return View("~/Views/Other/Index.cshtml"); }
3.2.2 输出带数据的视图
3.2.2.1 使用ViewBag 动作函数
public ViewResult Index() {
ViewBag.Message = "Hello"; ViewBag.Date = DateTime.Now; return View(); }
视图
@{
ViewBag.Title = "Index"; }
<h2>Index</h2>
The day is: @ViewBag.Date.DayOfWeek <p />
The message is: @ViewBag.Message <p />
3.2.2.2 使用变量 动作函数
public ViewResult Index() {
ViewData["Message"] = "Hello"; ViewData["Date"] = DateTime.Now;
ViewBag.Days = new[] { "Monday", "Tuesday", "Wednesday", "Etc" }; ViewBag.Fruits = new[] { "Apples", "Mango", "Bannana" };
List<Region> regionsData = new List<Region> {
new Region { RegionID = 7, RegionName = "Northern" }, new Region { RegionID = 3, RegionName = "Central" }, new Region { RegionID = 5, RegionName = "Southern" }, };
ViewData["region"] = new SelectList(regionsData, // items "RegionID", // dataValueField "RegionName", // dataTextField 0);
return View(); }
上一篇:S3C44B0 学习板使用指南
下一篇:朗文交互英语第二级A2答案