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
- $('#_btnSubmit').on('click', function () {
- var listofsubjects = new Array();
- alert('This is Inner html');
- debugger;
- $('#tbodyGridBoard tbody tr').each(function () {
- var row = $(this);
- var listofsubject = {};
- listofsubject.Subject_Name = row.find('td').eq(1).html();
- listofsubject.Sub_MaxMarks = row.find('td').eq(2).html();
- listofsubject.Sub_Scored = row.find('td').eq(3).html();
- debugger;
- listofsubjects.push(listofsubject);
- });
- $.ajax({
- type: 'POST',
- url: 'Dropdown/Submit',
- datatype: 'JSON',
- contentType: 'application/json; charset=utf-8',
- data: JSON.stringify(listofsubjects),
- success: function (r) {
- alert('Saved Successfully');
- }
- });
- });
Controller :
- int Currentid = 0;
- [HttpPost]
- public ActionResult Submit(StudentViewModel svm, FormCollection fc)
- {
- if (ModelState.IsValid)
- {
- DatabaseDal dal = new DatabaseDal();
- svm.studentDetails.postAppliedFor = fc["SelectedText"].ToString();
- dal.Studentdetails.Add(svm.studentDetails);
- dal.SaveChanges();
- Currentid = svm.studentDetails.Saveid;
-
- svm.SaveSubjects.Save_ID = Currentid;
- dal.SaveSubjectsList.Add(svm.SaveSubjects);
- dal.SaveChanges();
- }
- return View("ApplicationEnter", svm);
- }
Highlighted text is used for saving html table values to another table.