Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. @model ExamBankSys.Models.ProposalViewModels
  2.  
  3. <table class="table">
  4. <tr>
  5. <td>
  6. @Html.DisplayName("Question")
  7. </td>
  8. <td>
  9. @Html.DisplayName("Marks")
  10. </td>
  11. </tr>
  12.  
  13. @foreach (var item in Model.Questions)
  14. {
  15. <tr>
  16. <td>
  17. @Html.DisplayFor(model => item.Question)
  18. </td>
  19. <td>
  20. @Html.DisplayFor(model => item.Marks)
  21. </td>
  22. </tr>
  23. }
  24. </table>
  25.  
  26. public class ProposalViewModels
  27. {
  28. public int id { get; set; }
  29.  
  30. public virtual ICollection<Question> Questions { get; set; }
  31. }
  32.  
  33. [HttpPost]
  34. [ValidateAntiForgeryToken]
  35. public ActionResult Create([Bind(Include = "id,Questions")] ProposalViewModels viewModel)
  36. {
  37. if (ModelState.IsValid)
  38. {
  39. var proposal = new Proposal
  40. {
  41. id = viewModel.id,
  42. Questions = viewModel.Questions,
  43. };
  44.  
  45. db.Proposals.Add(proposal);
  46. db.SaveChanges();
  47.  
  48. return RedirectToAction("Index");
  49. }
  50. return View();
  51. }
  52.  
  53. public ActionResult LoadQuestions(int id)
  54. {
  55. var model = new ProposalViewModels();
  56. model.Questions = listofQuestions();
  57.  
  58. return PartialView("~/Views/Proposals/_Proposal.cshtml", model);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement