|
edit and delete buttons. Только начинаю, поэтому извините
|
|||
---|---|---|---|
#18+
Извиняюсь что выкладываю весь код. Почему у меня View Edit и Delete buttons не работают? Хотя та же самая Create button созданная с помощью мастера работает. public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Table1 table1 = db.Table1.Find(id); if (table1 == null) { return HttpNotFound(); } return View(table1); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include="ORDER_ID,CODE_RP,STATUS_RP,Family,Name,Otchestvo,Photo")] Table1 table1) { if (ModelState.IsValid) { db.Entry(table1).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(table1); } // GET: /Table1/Delete/5 public ActionResult Delete(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Table1 table1 = db.Table1.Find(id); if (table1 == null) { return HttpNotFound(); } return View(table1); } // POST: /Table1/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { Table1 table1 = db.Table1.Find(id); db.Table1.Remove(table1); db.SaveChanges(); return RedirectToAction("Index"); } Вот сами Views: Edit: @model RGPMVD.Models.Table1 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Edit</title> </head> <body> <script src="~/Scripts/jquery-1.10.2.min.js"></script> <script src="~/Scripts/jquery.validate.min.js"></script> <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Table1</h4> <hr /> @Html.ValidationSummary(true) @Html.HiddenFor(model => model.ORDER_ID) @Html.HiddenFor(model => model.CODE_RP) <div class="form-group"> @Html.LabelFor(model => model.STATUS_RP, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.STATUS_RP) @Html.ValidationMessageFor(model => model.STATUS_RP) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Family, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Family) @Html.ValidationMessageFor(model => model.Family) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Otchestvo, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Otchestvo) @Html.ValidationMessageFor(model => model.Otchestvo) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Photo, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Photo) @Html.ValidationMessageFor(model => model.Photo) </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> </body> </html> Delete: @model RGPMVD.Models.Table1 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Delete</title> </head> <body> <h3>Are you sure you want to delete this?</h3> <div> <h4>Table1</h4> <hr /> <dl class="dl-horizontal"> <dt> @Html.DisplayNameFor(model => model.STATUS_RP) </dt> <dd> @Html.DisplayFor(model => model.STATUS_RP) </dd> <dt> @Html.DisplayNameFor(model => model.Family) </dt> <dd> @Html.DisplayFor(model => model.Family) </dd> <dt> @Html.DisplayNameFor(model => model.Name) </dt> <dd> @Html.DisplayFor(model => model.Name) </dd> <dt> @Html.DisplayNameFor(model => model.Otchestvo) </dt> <dd> @Html.DisplayFor(model => model.Otchestvo) </dd> <dt> @Html.DisplayNameFor(model => model.Photo) </dt> <dd> @Html.DisplayFor(model => model.Photo) </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> </body> </html> ... |
|||
:
Нравится:
Не нравится:
|
|||
15.06.2014, 17:08 |
|
edit and delete buttons. Только начинаю, поэтому извините
|
|||
---|---|---|---|
#18+
Код: c# 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.
Вот сами Views: Edit: Код: html 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.
Delete: Код: html 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.
... |
|||
:
Нравится:
Не нравится:
|
|||
16.06.2014, 10:47 |
|
edit and delete buttons. Только начинаю, поэтому извините
|
|||
---|---|---|---|
#18+
Ну вот в коде обработки Edit есть вот такое: db.Entry(table1).State = EntityState.Modified; db.SaveChanges(); А в коде Delete - только найти таблицу и все. Надо же добавить чтото типа db.DeleteTable(....) db.SaveChanges(); чтобы стиралось.... ? ... |
|||
:
Нравится:
Не нравится:
|
|||
16.06.2014, 10:52 |
|
|
start [/forum/topic.php?fid=20&fpage=117&tid=1402814]: |
0ms |
get settings: |
11ms |
get forum list: |
12ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
31ms |
get topic data: |
10ms |
get forum data: |
2ms |
get page messages: |
40ms |
get tp. blocked users: |
2ms |
others: | 325ms |
total: | 439ms |
0 / 0 |