Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8868295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:14:17+00:00 2026-06-14T17:14:17+00:00

I have a datatable in my view, i need to pass values from datatable

  • 0

I have a datatable in my view, i need to pass values from datatable to controller on submit button. In the case of textboxes, it is working fine. I’ve trouble in passing values from dropdownlist as well as checkbox.

My view side code,

<script type="text/javascript" charset="utf-8">
  $(document).ready(function () {
  $.get(
  '/Food/GetAllChild',
  function (data) {
  var htmlstmp = "";
  for (var i = 0; i < data.length; i = i + 1) {
    //Add rows to the datatable as per number of items in database
    htmlstmp += "<tr>"; 
    htmlstmp += " <td>";
    htmlstmp += "<div class='divslno'><div class='tdlabel'>" + data[i].ChildId +"</div> </div>";
    htmlstmp += "</td>"; 
    htmlstmp += "<td><div class='divdeliveryitem'><select class='fordivdeliveryitemselector' id='" + data[i].ChildId + "'>";
    htmlstmp += "<option class='foodlist'>Select</option>";
    htmlstmp += "<option class='foodlist'>Menu 1</option>";
    htmlstmp += "</select></div></td>";
    htmlstmp += "<td>";     
    htmlstmp += "<div class='deliverystatusrow1'> <input type='checkbox' class='deliverystatuschb' value='false' /></div>";
    htmlstmp += "</td>";
    htmlstmp += "</tr>";
  }

  //Append "htmlstmp" to the datatable's tbody. childfoodattendancetbody is id of tbody
$('#childfoodattendancetbody').append(htmlstmp);
     var oTable = $('#example').dataTable({
     "iDisplayLength": 5,
     "bSort": false
  }); 
$("#btnsaveall").click(function () {
   var datatopost = new Object(); 
  $("#example .row_selected").each(function (i, item) {
     var chidltdid = $(item).find("td .tdlabel:eq(0)").html();
     datatopost["[" + i + "].ChildId"] = chidltdid;
     datatopost["[" + i + "].FoodMenuId"] = $(item).find("td .fordivdeliveryitemselector#"+chidltdid+" :eq(1)").html(); 
     datatopost["[" + i + "].FoodDelivery_Status"] = $(item).find("td .deliverystatuschb :eq(2)").attr("value");
   }); 
});
 $.ajax({
    url: '@Url.Action("InsertData")',
    type: 'POST',
    traditional: true,
    data: datatopost,
    dataType: "html",
    success: function (response) {
  }
 });

 });
});

 </script>

Datapost variable is showing following values, when i checked via chrome inspect element

[0].ChildId: "1"
[0].FoodDelivery_Status: undefined
[0].FoodMenuId: undefined
[1].ChildId: "2"
[1].FoodDelivery_Status: undefined
[1].FoodMenuId: undefined

My action looks like,

[HttpPost]
public ActionResult InsertData(List<FoodDelivery> fooddelivery)
{
    int _childid, _menu;
    bool _deliverystatus;           
    for (int i = 0; i < fooddelivery.Count; i++)
    {
        _childid = fooddelivery[i].ChildId;
        _deliverystatus = fooddelivery[i].FoodDelivery_Status;
        _menu = fooddelivery[i].FoodMenuId;
            // Code to insert to database

      }
      return View();
   }

What am i doing wrong here?

Please help,

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:14:19+00:00Added an answer on June 14, 2026 at 5:14 pm

    Change tablebody rendering to razor syndax instead of Jquery and assign each control an ID to be easier to find it’s value.

    Try this

    var selectValMenuItem = $('.fordivdeliveryitemselector#' + chidltdid + ' :selected').val();                                        
    
    var delvstatus = $('input[id=' + chidltdid+']').attr('checked');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list view which is bound to a DataTable source. The sorting
I have datatable with column name tag and 100 rows of data.I need to
I have a datatable that stores location values as such: CTY_CD, STATE_CD, COUNTRY_CD and
I need to add a second DataTable from our app's main DataSet into a
I need to extract data from a third party system (I have no influence
I have 3 openFaces <o:datatable /> s in the same view page (overview.xhtml). The
I already have the datatable. I just need to fill it in the list
I have a datatable from some source which the structor bookid title author The
I need to integrate between KnockoutJS with YUI. I have some view models created
I have pages of data, pulled from a database. I need to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.