标签:style blog http color io 使用 ar for strong
Part I:提问
===========================
1.要将“Hello, Admin",从控制器传递到视图,该如何操作?
(1)使用ViewData
(2)使用ViewBag
2.已知某学生类Student.cs,控制器中Index动作将学生传递给视图,请解释强类型传递的原理。
public ActionResult Index() { return View(db.Students.ToList()); }
@model IEnumerable<tempPractice.Models.Student> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table> <tr> <th> @Html.DisplayNameFor(model => model.Name) </th> <th> @Html.DisplayNameFor(model => model.StuNo) </th> <th> @Html.DisplayNameFor(model => model.Phone) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.DisplayFor(modelItem => item.StuNo) </td> <td> @Html.DisplayFor(modelItem => item.Phone) </td> <td> @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | @Html.ActionLink("Details", "Details", new { id=item.Id }) | @Html.ActionLink("Delete", "Delete", new { id=item.Id }) </td> </tr> } </table>
Part II:Ch03 视图3
===========================
要点:
标签:style blog http color io 使用 ar for strong
原文地址:http://www.cnblogs.com/meetyy/p/4009389.html