■ 엔터티 프레임워크(Entity Framework)를 사용해 ASP.NET MVC 애플리케이션을 만드는 방법을 보여준다.
▶ Room.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using System.Collections.Generic; namespace TestProject.Models { /// <summary> /// 회의실 /// </summary> public class Room { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 회의실 ID - RoomID /// <summary> /// 회의실 ID /// </summary> public int RoomID { get; set; } #endregion #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 스피커 컬렉션 - SpeakerCollection /// <summary> /// 스피커 컬렉션 /// </summary> public virtual ICollection<Speaker> SpeakerCollection { get; set; } #endregion } } |
▶ Speaker.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
namespace TestProject.Models { /// <summary> /// 스피커 /// </summary> public class Speaker { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 스피커 ID - SpeakerID /// <summary> /// 스피커 ID /// </summary> public int SpeakerID { get; set; } #endregion #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 회의실 ID - RoomID /// <summary> /// 회의실 ID /// </summary> public int RoomID { get; set; } #endregion #region 회의실 - Room /// <summary> /// 회의실 /// </summary> public virtual Room Room { get; set; } #endregion } } |
▶ TestProjectContext.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
using System.Data.Entity; using TestProject.Models; namespace TestProject.Data { /// <summary> /// 테스트 프로젝트 컨텍스트 /// </summary> public class TestProjectContext : DbContext { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 방 DB 집합 - RoomDBSet /// <summary> /// 방 DB 집합 /// </summary> public DbSet<Room> RoomDBSet { get; set; } #endregion #region 스피커 DB 집합 - SpeakerDBSet /// <summary> /// 스피커 DB 집합 /// </summary> public DbSet<Speaker> SpeakerDBSet { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - TestProjectContext() /// <summary> /// 생성자 /// </summary> public TestProjectContext() : base("name=TestProjectContext") { } #endregion } } |
▶ HomeController.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
using System.Web.Mvc; namespace TestProject.Controllers { /// <summary> /// HOME 컨트롤러 /// </summary> public class HomeController : Controller { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 인덱스 페이지 처리하기 - Index() /// <summary> /// 인덱스 페이지 처리하기 /// </summary> /// <returns>액션 결과</returns> public ActionResult Index() { return View(); } #endregion #region 소개 페이지 처리하기 - About() /// <summary> /// 소개 페이지 처리하기 /// </summary> /// <returns>액션 결과</returns> public ActionResult About() { ViewBag.Message = "Your application description page."; return View(); } #endregion #region 연락처 페이지 처리하기 - Contact() /// <summary> /// 연락처 페이지 처리하기 /// </summary> /// <returns>액션 결과</returns> public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); } #endregion } } |
▶ RoomController.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
using System.Data.Entity; using System.Linq; using System.Net; using System.Web.Mvc; using TestProject.Data; using TestProject.Models; namespace TestProject.Controllers { /// <summary> /// 회의실 컨트롤러 /// </summary> public class RoomController : Controller { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 컨텍스트 /// </summary> private TestProjectContext context = new TestProjectContext(); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 인덱스 페이지 처리하기 - Index() [GET : Room] /// <summary> /// 인덱스 페이지 처리하기 /// </summary> /// <returns>액션 결과</returns> public ActionResult Index() { return View(this.context.RoomDBSet.ToList()); } #endregion #region 상세 페이지 처리하기 - Details(id) [GET : Room/Details/5] /// <summary> /// 상세 페이지 처리하기 /// </summary> /// <param name="id">ID</param> /// <returns>액션 결과</returns> public ActionResult Details(int? id) { if(id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Room room = this.context.RoomDBSet.Find(id); if(room == null) { return HttpNotFound(); } return View(room); } #endregion #region 생성 페이지 처리하기 - Create() [GET : Room/Create] /// <summary> /// 생성 페이지 처리하기 /// </summary> /// <returns>액션 결과</returns> public ActionResult Create() { return View(); } #endregion #region 생성 페이지 처리하기 - Create(room) [POST : Room/Create] /// <summary> /// 생성 페이지 처리하기 /// </summary> /// <param name="room">회의실</param> /// <returns>액션 결과</returns> [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "RoomID,Name")] Room room) { if(ModelState.IsValid) { this.context.RoomDBSet.Add(room); this.context.SaveChanges(); return RedirectToAction("Index"); } return View(room); } #endregion #region 편집 페이지 처리하기 - Edit(id) [GET : Room/Edit/5] /// <summary> /// 편집 페이지 처리하기 /// </summary> /// <param name="id">ID</param> /// <returns>액션 결과</returns> public ActionResult Edit(int? id) { if(id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Room room = this.context.RoomDBSet.Find(id); if(room == null) { return HttpNotFound(); } return View(room); } #endregion #region 편집 페이지 처리하기 - Edit(room) [POST : Room/Edit/5] /// <summary> /// 편집 페이지 처리하기 /// </summary> /// <param name="room">회의실</param> /// <returns>액션 결과</returns> [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "RoomID,Name")] Room room) { if(ModelState.IsValid) { this.context.Entry(room).State = EntityState.Modified; this.context.SaveChanges(); return RedirectToAction("Index"); } return View(room); } #endregion #region 삭제 페이지 처리하기 - Delete(id) [GET : Room/Delete/5] /// <summary> /// 삭제 페이지 처리하기 /// </summary> /// <param name="id">ID</param> /// <returns>액션 결과</returns> public ActionResult Delete(int? id) { if(id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Room room = this.context.RoomDBSet.Find(id); if(room == null) { return HttpNotFound(); } return View(room); } #endregion #region 확인시 삭제 페이지 처리하기 - DeleteConfirmed(id) [POST : Room/Delete/5] /// <summary> /// 확인시 삭제 페이지 처리하기 /// </summary> /// <param name="id">ID</param> /// <returns>액션 결과</returns> [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { Room room = this.context.RoomDBSet.Find(id); this.context.RoomDBSet.Remove(room); this.context.SaveChanges(); return RedirectToAction("Index"); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 리소스 해제하기 - Dispose(disposing) /// <summary> /// 리소스 해제하기 /// </summary> /// <param name="disposing">리소스 해제 여부</param> protected override void Dispose(bool disposing) { if(disposing) { this.context.Dispose(); } base.Dispose(disposing); } #endregion } } |
▶ SpeakerController.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
using System.Data.Entity; using System.Linq; using System.Net; using System.Web.Mvc; using TestProject.Data; using TestProject.Models; namespace TestProject.Controllers { /// <summary> /// 스피커 컨트롤러 /// </summary> public class SpeakerController : Controller { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 컨텍스트 /// </summary> private TestProjectContext context = new TestProjectContext(); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 인덱스 페이지 처리하기 - Index() [GET : Speaker] /// <summary> /// 인덱스 페이지 처리하기 /// </summary> /// <returns>액션 결과</returns> public ActionResult Index() { IQueryable<Speaker> speakerQueryable = this.context.SpeakerDBSet.Include(s => s.Room); return View(speakerQueryable.ToList()); } #endregion #region 상세 페이지 처리하기 - Details(id) [GET : Speaker/Details/5] /// <summary> /// 상세 페이지 처리하기 /// </summary> /// <param name="id">ID</param> /// <returns>액션 결과</returns> public ActionResult Details(int? id) { if(id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Speaker speaker = this.context.SpeakerDBSet.Find(id); if(speaker == null) { return HttpNotFound(); } return View(speaker); } #endregion #region 생성 페이지 처리하기 - Create() [GET : Speaker/Create] /// <summary> /// 생성 페이지 처리하기 /// </summary> /// <returns>액션 결과</returns> public ActionResult Create() { ViewBag.RoomID = new SelectList(this.context.RoomDBSet, "RoomID", "Name"); return View(); } #endregion #region 생성 페이지 처리하기 - Create(speaker) [POST : Speaker/Create] /// <summary> /// 생성 페이지 처리하기 /// </summary> /// <param name="speaker">스피커</param> /// <returns>액션 결과</returns> [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "SpeakerID,Name,RoomID")] Speaker speaker) { if(ModelState.IsValid) { this.context.SpeakerDBSet.Add(speaker); this.context.SaveChanges(); return RedirectToAction("Index"); } ViewBag.RoomID = new SelectList(this.context.RoomDBSet, "RoomID", "Name", speaker.RoomID); return View(speaker); } #endregion #region 편집 페이지 처리하기 - Edit(id) [GET : Speaker/Edit/5] /// <summary> /// 편집 페이지 처리하기 /// </summary> /// <param name="id">ID</param> /// <returns>액션 결과</returns> public ActionResult Edit(int? id) { if(id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Speaker speaker = this.context.SpeakerDBSet.Find(id); if(speaker == null) { return HttpNotFound(); } ViewBag.RoomID = new SelectList(this.context.RoomDBSet, "RoomID", "Name", speaker.RoomID); return View(speaker); } #endregion #region 편집 페이지 처리하기 - Edit(speaker) [POST : Speaker/Edit/5] /// <summary> /// 편집 페이지 처리하기 /// </summary> /// <param name="speaker">스피커</param> /// <returns>액션 결과</returns> [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "SpeakerID,Name,RoomID")] Speaker speaker) { if(ModelState.IsValid) { this.context.Entry(speaker).State = EntityState.Modified; this.context.SaveChanges(); return RedirectToAction("Index"); } ViewBag.RoomID = new SelectList(this.context.RoomDBSet, "RoomID", "Name", speaker.RoomID); return View(speaker); } #endregion #region 삭제 페이지 처리하기 - Delete(id) [GET : Speaker/Delete/5] /// <summary> /// 삭제 페이지 처리하기 /// </summary> /// <param name="id">ID</param> /// <returns>액션 결과</returns> public ActionResult Delete(int? id) { if(id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Speaker speaker = this.context.SpeakerDBSet.Find(id); if(speaker == null) { return HttpNotFound(); } return View(speaker); } #endregion #region 확인시 삭제 페이지 처리하기 - DeleteConfirmed(id) [POST : Speaker/Delete/5] /// <summary> /// 확인시 삭제 페이지 처리하기 /// </summary> /// <param name="id">ID</param> /// <returns>액션 결과</returns> [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { Speaker speaker = this.context.SpeakerDBSet.Find(id); this.context.SpeakerDBSet.Remove(speaker); this.context.SaveChanges(); return RedirectToAction("Index"); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 리소스 해제하기 - Dispose(disposing) /// <summary> /// 리소스 해제하기 /// </summary> /// <param name="disposing">리소스 해제 여부</param> protected override void Dispose(bool disposing) { if(disposing) { this.context.Dispose(); } base.Dispose(disposing); } #endregion } } |
▶ Room/Index.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
@model IEnumerable<TestProject.Models.Room> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.Name) </th> <th></th> </tr> @foreach(var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.ActionLink("Edit", "Edit", new { id = item.RoomID }) | @Html.ActionLink("Details", "Details", new { id = item.RoomID }) | @Html.ActionLink("Delete", "Delete", new { id = item.RoomID }) </td> </tr> } </table> |
▶ Room/Create.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
@model TestProject.Models.Room @{ ViewBag.Title = "Create"; } <h2>Create</h2> @using(Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Room</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.Name, htmlAttributes : new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> } <div> @Html.ActionLink("Back to List", "Index") </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") } |
▶ Room/Edit.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
@model TestProject.Models.Room @{ ViewBag.Title = "Edit"; } <h2>Edit</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Room</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.RoomID) <div class="form-group"> @Html.LabelFor(model => model.Name, htmlAttributes : new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Save" class="btn btn-default" /> </div> </div> </div> } <div> @Html.ActionLink("Back to List", "Index") </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") } |
▶ Room/Details.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
@model TestProject.Models.Room @{ ViewBag.Title = "Details"; } <h2>Details</h2> <div> <h4>Room</h4> <hr /> <dl class="dl-horizontal"> <dt> @Html.DisplayNameFor(model => model.Name) </dt> <dd> @Html.DisplayFor(model => model.Name) </dd> </dl> </div> <p> @Html.ActionLink("Edit", "Edit", new { id = Model.RoomID }) | @Html.ActionLink("Back to List", "Index") </p> |
▶ Room/Delete.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
@model TestProject.Models.Room @{ ViewBag.Title = "Delete"; } <h2>Delete</h2> <h3>Are you sure you want to delete this?</h3> <div> <h4>Room</h4> <hr /> <dl class="dl-horizontal"> <dt> @Html.DisplayNameFor(model => model.Name) </dt> <dd> @Html.DisplayFor(model => model.Name) </dd> </dl> @using(Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-actions no-color"> <input type="submit" value="Delete" class="btn btn-default" /> | @Html.ActionLink("Back to List", "Index") </div> } </div> |
▶ Speaker/Index.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
@model IEnumerable<TestProject.Models.Speaker> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.Room.Name) </th> <th> @Html.DisplayNameFor(model => model.Name) </th> <th></th> </tr> @foreach(var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Room.Name) </td> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.ActionLink("Edit", "Edit", new { id = item.SpeakerID }) | @Html.ActionLink("Details", "Details", new { id = item.SpeakerID }) | @Html.ActionLink("Delete", "Delete", new { id = item.SpeakerID }) </td> </tr> } </table> |
▶ Speaker/Create.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
@model TestProject.Models.Speaker @{ ViewBag.Title = "Create"; } <h2>Create</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Speaker</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.Name, htmlAttributes : new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.RoomID, "RoomID", htmlAttributes : new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownList("RoomID", null, htmlAttributes : new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.RoomID, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> } <div> @Html.ActionLink("Back to List", "Index") </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") } |
▶ Speaker/Edit.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
@model TestProject.Models.Speaker @{ ViewBag.Title = "Edit"; } <h2>Edit</h2> @using(Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Speaker</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.SpeakerID) <div class="form-group"> @Html.LabelFor(model => model.Name, htmlAttributes : new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.RoomID, "RoomID", htmlAttributes : new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownList("RoomID", null, htmlAttributes : new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.RoomID, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Save" class="btn btn-default" /> </div> </div> </div> } <div> @Html.ActionLink("Back to List", "Index") </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") } |
▶ Speaker/Details.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
@model TestProject.Models.Speaker @{ ViewBag.Title = "Details"; } <h2>Details</h2> <div> <h4>Speaker</h4> <hr /> <dl class="dl-horizontal"> <dt> @Html.DisplayNameFor(model => model.Room.Name) </dt> <dd> @Html.DisplayFor(model => model.Room.Name) </dd> <dt> @Html.DisplayNameFor(model => model.Name) </dt> <dd> @Html.DisplayFor(model => model.Name) </dd> </dl> </div> <p> @Html.ActionLink("Edit", "Edit", new { id = Model.SpeakerID }) | @Html.ActionLink("Back to List", "Index") </p> |
▶ Speaker/Delete.cshtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
@model TestProject.Models.Speaker @{ ViewBag.Title = "Delete"; } <h2>Delete</h2> <h3>Are you sure you want to delete this?</h3> <div> <h4>Speaker</h4> <hr /> <dl class="dl-horizontal"> <dt> @Html.DisplayNameFor(model => model.Room.Name) </dt> <dd> @Html.DisplayFor(model => model.Room.Name) </dd> <dt> @Html.DisplayNameFor(model => model.Name) </dt> <dd> @Html.DisplayFor(model => model.Name) </dd> </dl> @using(Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-actions no-color"> <input type="submit" value="Delete" class="btn btn-default" /> | @Html.ActionLink("Back to List", "Index") </div> } </div> |