Skip to content
Loading
  
  • class="modal-footer">  
  • "#" class="btn btn-default" data-dismiss="modal">Cancel  
  • "#" class="btn btn-success" onclick="Delete()">Confirm  
  •   
  •   
  •   
  •   
  •    
  • step 3.
    1. function OpenPopUp(Id)  
    2. {  
    3. $("#txtId").val(Id);  
    4. $("#DeleteModal").Modal('open');  
    5.   
    6. }  
    step 4. 
    1. function Delete(e)  
    2. {  
    3. e.preventDefault();
    4. var Id= $("#txtId").val()  
    5. $.Post("/home/Delete?Id"+Id,function(data){  
    6. alert(data);  
    7. });  
    8. }  
     Note :- when using href="#" and onclick function then best practise is to use below code everywhere in the application
    1. $('#myLink').click(function(){ MyFunction(); return false; });  
     where MyFunction() is any function or directly your code like ajax post etc.
    +1
  • +1
    Hi Sachin
     
      I can't do like this using data-toggle & data-target. I have tried & it is working
     
    @if (item.IsActive)
    {
    }
    else
    {
    }
     
    Thanks 
    +1
  • Rijwan Ansari
    +1
    You can do like this:
     
    1. "deleteItem" class="deleteItem" data-target="#basic"   
    2.                     data-toggle="modal"   
    3.                     data-path="@Url.Action("Delete", "MyController", new { id = @item.id })">Delete  
    Modal Html
     
    1. class="modal fade" id="basic" tabindex="-1" role="basic" aria-hidden="true" style="display: none;">  
    2. class="modal-dialog">  
    3.     class="modal-content">  
    4.         class="modal-header">  
    5.             "button" class="close" data-dismiss="modal" aria-hidden="true">  
    6.             class="modal-title">Delete Confirmation  
    7.         
      
  •         class="modal-body">  
  •             Are you sure you want to delete this item?  
  •           
  •         class="modal-footer">  
  •             "modal" type="button" class="btn btn-default">Cancel  
  •             "btnContinueDelete" type="button" class="btn btn-primary">Delete  
  •           
  •       
  •   
  • Js part:
    1.   
    And controller sample
     
    1. // GET: MyController/Delete  
    2. [HttpGet]  
    3. public ActionResult Delete(int id)  
    4. {  
    5.     var model = Context.my_models.Where(x => x.id == id).FirstOrDefault();  
    6.     if (model != null)  
    7.     {  
    8.         Context.my_models.DeleteOnSubmit(model);  
    9.         Context.SubmitChanges();  
    10.   
    11.         return RedirectToAction("List");  
    12.     }  
    13.   
    14.     return new HttpNotFoundResult();  
    15. }  
     
    +1
  • +1
    Hi Sachin/Rizwan
     
      Can't i do like this using - data-toggle="modal" data-target="#DeleteModal"
     
    Hi Sachin
    I can't do like this using data-toggle & data-target. I have tried & it is working
    Thanks
     
    Thanks 
    +1