Skip to content
Loading
Save local values to database using asp.net mvc5?  
  • On Concroller  
  •   
  •  public IActionResult Save(Incident_NameDropDown model)  
  •      {  
  •       using (Dbcontext db = new Dbcontext())  
  •             {  
  •                 tableName tbObj = new tableName  
  •                 {  
  •                     Title = model.Title,  
  •                     Description = model.Description,  
  •                     Description = model.Description,  
  •                 };  
  •                 db.tableName.Add(tbObj);  
  •                 db.SaveChanges();  
  •             }  
  •         }  
  • +1
  • Vikas
     
    Say  if you have date created as Datepicker, like user creates manually, How from the Controller side will this be implemented? Meaning how will the values be stored to the local database that is also next task after this work around?
    +1
  • Vikas Panwar
     public IActionResult Save(Incident_NameDropDown model)
         {
          using (Dbcontext db = new Dbcontext())
                {
                    tableName tbObj = new tableName
                    {
                        Title = model.Title,
                        Description = model.Description,
                    };
                    db.tableName.Add(tbObj);
                    db.SaveChanges();
                }
            }
    +1
  • Sachin
     
    For the send functionality from View side, how do i implement using Ajax? 
    +1
  • Sachin Singh
    Test this
    1. public IActionResult Save(Incedent_NameDropDown obj)  
    2. {  
    3.  _context.Incedent_NameDropDowns.Add(obj);  
    4. _Context.Save();  
    5. return view("anyview");  
    6. }  
     Send value to controller either using form or Ajax.
    +1