Click here to Skip to main content
15,912,457 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have get values from list box which is in the form in one variable.and i want to send it to crate method of controller.
on submit button click i have collect id's of book in one variable.and i have to send that variable to post method to save in multiple rows which each row contain different bookid of same student.
I want to send 'BookIDs' variable to controller.

here is the on click submit button function

JavaScript
var BookIDs = "";
  var BookName = "";
  $("#submit").live("click", function () {
      var values = [];
      $('#LstSignInAuthority').each(function (i, option) {
          values[i] = $(option).text();
          //            alert(values);

          $('#LstSignInAuthority option').each(function (i, selected) {
              BookIDs = BookIDs + $(selected).val() + ",";
              alert(BookIDs);
          });
      });
      SaveBook();

  });


here is my post method

C#
public ActionResult Create(FormCollection fc)//Student_Fee_Master Student_Fee_MasterObj
      {


          //foreach (var key in fc.AllKeys)
          //{
          //    var value = fc[key];
          //}
          long acadamicId = Convert.ToInt64(fc["Academic_year_Id"]);
          long classId = Convert.ToInt64(fc["Class_Id"]);
          long secId = Convert.ToInt64(fc["Section_Id"]);
          //var regid = fc["Student_Name"];

          var regid1 = fc["Registration_Id"];
          //long id = long.Parse(regid1);
          long regid4 = Convert.ToInt64(regid1);
          var roll1 = fc["Roll_Id"];
          long roll2 = Convert.ToInt64(roll1);
          var Bookcat = fc["Book_Category_Id"];
          long Bookcat1 = Convert.ToInt64(Bookcat);

         //  long rollid = Convert.ToInt64(fc["Roll_Id"]);
          //string i = regid;
          var bkName = fc["Book_Name"];
          var Admission = fc["Admission_No"];
          string add_no = Admission;
          var roll = fc["Roll_number"];
          string roll3 = roll;
          List<long> bklst = new List<long>();
          foreach (long i in bklst)
          {
              var book = fc["Book_Id"];
              long book2 = Convert.ToInt64(book);
          }
         // string book1 = book;
          DateTime issue = Convert.ToDateTime(fc["Issue_Date"]);
          DateTime Return = Convert.ToDateTime(fc["Return_Date"]);
          bool status = Convert.ToBoolean(fc["Status"]);

              Student_Issue_Book Issue_Book_Obj = new Student_Issue_Book();
              Issue_Book_Obj.Creation_Date = DateTime.Now.ToUniversalTime();
              Issue_Book_Obj.Created_By = CurrentUserID;
              Issue_Book_Obj.Last_Updated_Date = DateTime.Now.ToUniversalTime();
              Issue_Book_Obj.Last_Updated_By = CurrentUserID;
              Issue_Book_Obj.Delete_Flag = false;


              Issue_Book_Obj.Academic_year_Id = acadamicId;
              Issue_Book_Obj.Class_Id = classId;
              Issue_Book_Obj.Section_Id = secId;
              Issue_Book_Obj.Book_Category_Id = Bookcat1;
              Issue_Book_Obj.Registration_Id = regid4;
              Issue_Book_Obj.Roll_Id = roll2;
              Issue_Book_Obj.Status = status;
              Issue_Book_Obj.Book_Id = book2;
               Issue_Book_Obj.Issue_Date = issue;
               Issue_Book_Obj.Return_Date = Return;
               Issue_Book_Obj.Status = status;
              db.Student_Issue_Book.AddObject(Issue_Book_Obj);
              db.SaveChanges();




          FillViewBag();
          ModelState.AddModelError("", "Book issued Successfully");
          return View();
      }
Posted
Updated 22-Mar-16 4:21am
v3
Comments
F-ES Sitecore 22-Mar-16 10:22am    
You don't need javascript to do this, if your code is using a submit button just use a normal form and normal model binding.
Hussain Javed 23-Mar-16 1:33am    
You can tell how can i use BookIDs variable values in create action method

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900