Skip to content
Loading
Error updating an entity: Conflict with Foreign Key  
  •                           
  •                       
  •                       
  •                         class="form-group">  
  •                             class="col-md-10">  
  •                                 "Status" asp-for="@item.Status" class="form-control">  
  •                                     "0">Operativo  
  •                                     "1">Nuevo Item  
  •                                     "2">Reparación  
  •                                   
  •                                 for="@item.Status" class="text-danger">  
  •                               
  •                           
  •                       
  •                       
  •                         "submit" value="Update" class="btn btn-default" />  
  •                       
  •                   
  •               
  •           
  •   
  •     }  
  •  
     
    I don't know if the dropdownlist for the Store might be sending a StoreID value wrong. It seems it's ok, so I don't know.
     
    Thanks in advance for any help.
     
    Update: More Info 
     
    I believe my problem could be on my Get Method.
     
    My view (Test.cshtml) is correctly loading and showing the info of all the items in the Machine class in the table, including the StoreID, however, my Get Method is this:
     
    1. public async Task Test()  
    2.         {  
    3.             PopulateMachineTypeDropDownListStore();  
    4.             return View(await _context.Machines.AsNoTracking().ToListAsync());  
    5.               
    6.         }  
    Is it possible that it does not matter if my View is showing what I want because my Get Method is not capturing any info on the StoreID? And thus, when I hit the 'Update' button it might be trying to duplicate the StoreID and for that I get the error?

    4 Replies

    Know the answer? Post it — somebody with the same question will find it here.