Ramco Ramco

Ramco Ramco

  • 443
  • 3.4k
  • 526.8k

Add Record when clicked Save in modal popup

Jun 3 2021 9:22 AM
Hi
 
Hi Sachin . How i can Add record in database with below code. I am using Ado.Net.
  1. @model IEnumerable<MyApplication.Models.Location>  
  2. <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" onclick="clearTextBox();"> <i class="fa fa-plus"></i> Add New</button><br /><br />  
  3. <table table table-striped table-bordered" style="width:100%" id="tblLocation">  
  4. <thead>  
  5. <tr>  
  6. <th>  
  7. @Html.DisplayNameFor(model => model.Id)  
  8. </th>  
  9. <th>  
  10. @Html.DisplayNameFor(model => model.Description)  
  11. </th>  
  12. <th>  
  13. @Html.DisplayNameFor(model => model.IsActive)  
  14. </th>  
  15. <th>Action</th>  
  16. </tr>  
  17. </thead>  
  18. <tbody>  
  19. @foreach (var item in Model)  
  20. {  
  21. <tr>  
  22. <td>  
  23. @Html.DisplayFor(modelItem => item.Id)  
  24. </td>  
  25. <td>  
  26. @Html.DisplayFor(modelItem => item.Description)  
  27. </td>  
  28. <td>  
  29. @Html.DisplayFor(modelItem => item.IsActive)  
  30. </td>  
  31. <td>  
  32. <a class='btn btn-primary btn-sm' id='btnEdit'><i class='fa fa-pencil'></i> Edit </a>  
  33. @if (item.IsActive.ToUpper() == "N")  
  34. {  
  35. <a class='btn btn-danger btn-sm disabled' id='btnDelete' style='margin-left:5px'><i class='fa fa-trash'></i> Delete</a>  
  36. }  
  37. else  
  38. {  
  39. <a class='btn btn-danger btn-sm' id='btnDelete' style='margin-left:5px'><i class='fa fa-trash'></i> Delete</a>  
  40. }  
  41. </td>  
  42. </tr>  
  43. }  
  44. </tbody>  
  45. </table>  
  46. <script src="~/Scripts/Appjs/Location.js"></script>  
  47. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">  
  48. <div class="modal-dialog">  
  49. <div class="modal-content">  
  50. <div class="modal-header">  
  51. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>  
  52. <h4 class="modal-title">Add New Location</h4>  
  53. </div>  
  54. <div class="modal-body">  
  55. <div class="form-horizontal">  
  56. <div class="form-group">  
  57. <label class="control-label col-sm-3" for="Id">Id</label>  
  58. <div class="col-sm-2">  
  59. <input type="text" class="form-control form-control-sm" id="txtId" placeholder="Id">  
  60. </div>  
  61. </div>  
  62. <div class="form-group">  
  63. <label class="control-label col-sm-3" for="Description">Description</label>  
  64. <div class="col-sm-9">  
  65. <input type="text" class="form-control form-control-sm" id="txtDescription" placeholder="Description">  
  66. </div>  
  67. </div>  
  68. <div class="form-group">  
  69. <label class="control-label col-sm-3" for="IsActive">Active</label>  
  70. <div class="col-sm-2">  
  71. <input type="text" class="form-control form-control-sm" id="txtIsActive" placeholder="Active">  
  72. </div>  
  73. </div>  
  74. </div>  
  75. </div>  
  76. <div class="modal-footer">  
  77. <button type="button" class="btn btn-primary" id="btnAdd" onclick="return Add();">Save</button>  
  78. <button type="button" class="btn btn-primary" id="btnUpdate" style="display:none;" onclick="Update();">Update</button>  
  79. <button type="button" class="btn btn-warning" data-dismiss="modal">Cancel</button>  
  80. </div>  
  81. </div>  
  82. </div>  
  83. </div>  
Thanks

Answers (1)