C# MVC 首頁列表action
阿新 • • 發佈:2018-11-21
1.action寫法: #region 列表首頁 public ActionResult Index() { YunWeiEntities db = new YunWeiEntities(); return View(db.vpnuserinfotest1.ToList()); } #endregion 2.試圖寫法 @model IEnumerable<haha20171114.EFmodel.vpnuserinfotest1> <h2>Index</h2> <h3>xxf Hello World!</h3> <p> @Html.ActionLink("建立", "Create") </p> <table> <tr> <th>自動ID</th> <th>姓名</th> <th>登入ID</th> <th>操作</th> </tr> @foreach (var item in Model) { <tr> <td>@item.ID</td> <td>@item.Name</td> <td>@item.UserID</td> <td> @Html.ActionLink("編輯", "Edit", new { id = item.ID }) | @Html.ActionLink("詳情", "Details", new { id = item.ID }) | @Html.ActionLink("刪除", "Delete", new { id = item.ID }) </td> </tr> } </table>