Senthil V

Senthil V

  • NA
  • 8
  • 401

Asp.net MVC - Reg.

Jul 12 2019 12:30 AM
Hi,
 
I want to know about how to pass textbox and HTML table values to the controller for saving in the database using entity framework... Please help me to do this. I am new to Asp.net MVC.
Jquery for passing HTML Table values
  1. $('#_btnSubmit').on('click'function () {  
  2. var listofsubjects = new Array();  
  3. alert('This is Inner html');  
  4. debugger;  
  5. $('#tbodyGridBoard tbody tr').each(function () {  
  6. var row = $(this);  
  7. var listofsubject = {};  
  8. listofsubject.Subject_Name = row.find('td').eq(1).html();  
  9. listofsubject.Sub_MaxMarks = row.find('td').eq(2).html();  
  10. listofsubject.Sub_Scored = row.find('td').eq(3).html();  
  11. debugger;  
  12. listofsubjects.push(listofsubject);  
  13. });  
  14. $.ajax({  
  15. type: 'POST',  
  16. url: 'Dropdown/Submit',  
  17. datatype: 'JSON',  
  18. contentType: 'application/json; charset=utf-8',  
  19. data: JSON.stringify(listofsubjects),  
  20. success: function (r) {  
  21. alert('Saved Successfully');  
  22. }  
  23. });  
  24. });  
Controller :
  1. int Currentid = 0;  
  2. [HttpPost]  
  3. public ActionResult Submit(StudentViewModel svm, FormCollection fc)  
  4. {  
  5. if (ModelState.IsValid)  
  6. {  
  7. DatabaseDal dal = new DatabaseDal();  
  8. svm.studentDetails.postAppliedFor = fc["SelectedText"].ToString();  
  9. dal.Studentdetails.Add(svm.studentDetails);  
  10. dal.SaveChanges();  
  11. Currentid = svm.studentDetails.Saveid;  
  12.   
  13. svm.SaveSubjects.Save_ID = Currentid;  
  14. dal.SaveSubjectsList.Add(svm.SaveSubjects);  
  15. dal.SaveChanges();  
  16. }  
  17. return View("ApplicationEnter", svm);  
  18. }  
Highlighted text is used for saving html table values to another table.

Answers (3)