Ramco Ramco

Ramco Ramco

  • 443
  • 3.4k
  • 526.8k

Validation on Modal

May 31 2021 3:38 PM
Hi
 
How to implement below Validation according to below Logic
 
 
 
  1. public JsonResult List()  
  2. {  
  3. List<Location> listLocation = new List<Location>();  
  4. var res = dbLocation.GetAllLocation().ToList();  
  5. foreach (var item in res)  
  6. {  
  7. Location obj = new Location();  
  8. obj.Id = item.Id;  
  9. obj.Description = item.Description;  
  10. obj.IsActive = item.IsActive;  
  11. listLocation.Add(obj);  
  12. }  
  13. return Json(listLocation, JsonRequestBehavior.AllowGet);  
  14. }  
  15. public JsonResult Add(Location objLocation)  
  16. {  
  17. if (ModelState.IsValid)  
  18. {  
  19. dbLocation.Add(objLocation);  
  20. return Json(new { success = true, message="Saved Successfully"});  
  21. }  
  22. return Json(dbLocation);  
  23. }  
Modal Popup
  1. <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 />  
  2. <table class="table table-striped table-bordered" style="width:100%" id="tblLocation">  
  3. <thead>  
  4. <tr>  
  5. <th>  
  6. ID  
  7. </th>  
  8. <th>  
  9. Description  
  10. </th>  
  11. <th>  
  12. Active  
  13. </th>  
  14. <th></th>  
  15. </tr>  
  16. </thead>  
  17. </table>  
  18. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">  
  19. <div class="modal-dialog">  
  20. <div class="modal-content">  
  21. <div class="modal-header">  
  22. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>  
  23. <h4 class="modal-title">Add New Location</h4>  
  24. </div>  
  25. <div class="modal-body">  
  26. <div class="form-horizontal">  
  27. <div class="form-group">  
  28. <label class="control-label col-sm-3" for="Id">Id</label>  
  29. <div class="col-sm-2">  
  30. <input type="text" class="form-control form-control-sm" id="txtId" placeholder="Id">  
  31. </div>  
  32. </div>  
  33. <div class="form-group">  
  34. <label class="control-label col-sm-3" for="Description">Description</label>  
  35. <div class="col-sm-9">  
  36. <input type="text" class="form-control form-control-sm" id="txtDescription" placeholder="Description">  
  37. </div>  
  38. </div>  
  39. <div class="form-group">  
  40. <label class="control-label col-sm-3" for="IsActive">Active</label>  
  41. <div class="col-sm-2">  
  42. <input type="text" class="form-control form-control-sm" id="txtIsActive" disabled placeholder="Active">  
  43. </div>  
  44. </div>  
  45. </div>  
  46. </div>  
  47. <div class="modal-footer">  
  48. @*<button type="button" class="btn btn-primary" id="btnAdd" onclick="return Add();"><span class="glyphicon glyphicon-ok"></span>Save</button>*@  
  49. <button type="button" class="btn btn-primary" id="btnAdd" onclick="return Add();">Save</button>  
  50. <button type="button" class="btn btn-primary" id="btnUpdate" style="display:none;" onclick="Update();">Update</button>  
  51. <button type="button" class="btn btn-warning" data-dismiss="modal">Cancel</button>  
  52. </div>  
  53. </div>  
  54. </div>  
  55. </div>  
Thanks

Answers (2)