Skip to content
Loading
  
  •                             class="modal-footer">  
  •                                 "button" class="btn btn-secondary" data-dismiss="modal">Cancel  
  •                                 "submit" class="btn btn-danger">Delete  
  •                               
  •                           
  •                       
  •                   
  •              
  •  step 2.  Create a method to return the above partial view
    1. public ActionResult GetPartialView(int Id=0)  
    2. {  
    3. if(Id==0)  
    4. {  
    5. return PartialView("_UpSert",new Customer());  
    6. }  
    7. else  
    8. {  
    9. Customer obj= new Customer();  
    10. using(SqlConnection con= new SqlConnection("constring"))  
    11. {  
    12. SqlCommand cmd= new SqlCommand("select 8 from Customer where Id=@Id");  
    13. cmd.Parameters.AddWithValue("@Id",Id);  
    14. con.Open();  
    15. SqlDataReader rdr= cmd.ExecuteReader();  
    16.   
    17. While(rdr.Read())  
    18. {  
    19. obj.Id= Convert.ToInt32(rdr[0]);  
    20. obj.Description= rdr[1].ToString();  
    21. obj.IsActive= Convert.ToBoolean(rdr[1]);  
    22.   
    23. }  
    24.   
    25. }  
    26. return PartialView("_UpSert",obj)  
    27. }  
    28.   
    29. }  
     step 3. On Add Click
    1. $("#Add").Click(function(){  
    2. $.get("/Controller/GetPartialView", function(data){  
    3. $("#AnyDiv").Html(data);  
    4. $("#UpSertModal").modal('open');  
    5. });  
    6.   
    7.   
    8. });  
     step 4. On Edit click
     
    1. $("#Edit").Click(function(){    
    2. var id= $(this).attr("data-Id");  
    3. $.get("/Controller/GetPartialView?Id="id, function(data){    
    4. $("#AnyDiv").Html(data);    
    5. $("#UpSertModal").modal('open');    
    6. });    
    7.     
    8.     
    9. });    
    0
  • Sachin Singh
    0
    anydiv is any div in your main view
    1. // main view  
    2. //add button  
    3. // table with data having two buttons edit and delete  
    4. "anyDiv">  
      
  •  
    0
  • Sachin Singh
    0

    add reference of Jquery in your main view or layout 

    and Html is small html

    $("#anyDiv").html(data);

    0
  • Sachin Singh
    0
    are you getting any errors on the console?
    0