Guest User

Untitled

a guest
Nov 24th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. public class DBM2BillingViewModel
  2. {
  3. public List<DatabaseM2> databaseM2List { get; set; }
  4.  
  5. [Display(Name = "Items")]
  6. public string Name { get; set; }
  7.  
  8. [Display(Name = "PO Item No.")]
  9. public int POItemNo { get; set; }
  10.  
  11. [Display(Name = "Date of Effect")]
  12. public DateTime DateOfEffect { get; set; }
  13.  
  14. [Display(Name = "Baseline Volume")]
  15. public float baselineVolume { get; set; }
  16.  
  17. [Display(Name = "Billing Month")]
  18. public string BillingMonth { get; set; }
  19.  
  20. [Display(Name = "Monthly Device Count")]
  21. public float DeviceCount { get; set; }
  22. }
  23.  
  24. **Controller**
  25. //Get Method
  26. public IActionResult Create()
  27. {
  28. DBM2BillingViewModel dbm2billingVM = new DBM2BillingViewModel();
  29. dbm2billingVM.databaseM2List = _context.databaseM2s.ToList();
  30. return View(dbm2billingVM);
  31. }
  32.  
  33. //Post Method
  34. [HttpPost]
  35. [ValidateAntiForgeryToken]
  36. public IActionResult Create(DBM2BillingViewModel model)
  37. {
  38. foreach(var dbm2 in model.databaseM2List)
  39. {
  40. DeviceBilling addModel = new DeviceBilling();
  41. addModel.Name = dbm2.Name;
  42. addModel.TrackName = "Database M2";
  43. addModel.POItemNo = dbm2.POItemNo;
  44. addModel.DateOfEffect = dbm2.DateOfEffect;
  45. addModel.baselineVolume = dbm2.BaselineVolume;
  46. addModel.BillingMonth = model.BillingMonth;
  47. addModel.DeviceCount = model.DeviceCount;
  48. _context.deviceBillings.Add(addModel);
  49. }
  50. _context.SaveChanges();
  51. return RedirectToAction(nameof(Index));
  52. }
  53. enter code here
  54.  
  55. @model FinancantPro.Models.DeviceCountModel.DBM2BillingViewModel
  56. @{
  57. ViewData["Title"] = "Create";
  58. }
  59.  
  60. <div class="container">
  61. <table class="table table-striped border">
  62. <thead>
  63. <tr class="table-info">
  64. <th>@Html.DisplayName("Item Name")</th>
  65. <th>@Html.DisplayName("PO Item No#")</th>
  66. <th>@Html.DisplayName("Date Of Effect")</th>
  67. <th>@Html.DisplayName("Baseline Volume")</th>
  68. <th>@Html.DisplayName("Billing Month")</th>
  69. <th>@Html.DisplayName("Device Count")</th>
  70. </tr>
  71. </thead>
  72.  
  73. <tbody>
  74. @for (int i = 0; i < Model.databaseM2List.Count; i++)
  75. {
  76. <tr>
  77. <td>
  78. @Html.HiddenFor(d => d.databaseM2List[i].Id)
  79. @Html.DisplayFor(d => d.databaseM2List[i].Name)
  80. </td>
  81. <td>
  82. @Html.DisplayFor(d => d.databaseM2List[i].POItemNo)
  83. </td>
  84. <td>
  85. @Html.DisplayFor(d => d.databaseM2List[i].DateOfEffect)
  86. </td>
  87. <td>
  88. @Html.DisplayFor(d => d.databaseM2List[i].BaselineVolume)
  89. </td>
  90. <td>
  91. @Html.TextBoxFor(d => d.BillingMonth, new { @class = "form-control" })
  92. </td>
  93. <td>
  94. @Html.TextBoxFor(d => d.DeviceCount, new { @class = "form-control" })
  95. </td>
  96. </tr>
  97. }
  98. </tbody>
  99. </table>
  100. <div class="form-group">
  101. <input type="submit" class="btn btn-primary" value="Create" />
  102.  
  103. </div>
  104. </div>
  105.  
  106. **************************
  107. If I add list in View I am not able to resolve the Model
Add Comment
Please, Sign In to add comment