Ajax将dropdownlist和checkbox的值从jquery数据表发布到控制器

Ajax将dropdownlist和checkbox的值从jquery数据表发布到控制器,jquery,datatable,asp.net-mvc-4,Jquery,Datatable,Asp.net Mvc 4,我的视图中有一个datatable,我需要在submit按钮上将值从datatable传递给控制器。就文本框而言,它工作正常。我很难从dropdownlist和复选框中传递值 我的视图侧代码 <script type="text/javascript" charset="utf-8"> $(document).ready(function () { $.get( '/Food/GetAllChild', function (data) { var htmlstmp

我的视图中有一个datatable,我需要在submit按钮上将值从datatable传递给控制器。就文本框而言,它工作正常。我很难从dropdownlist和复选框中传递值

我的视图侧代码

<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>
我的行为看起来像

[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();
   }
[HttpPost]
公共操作结果插入数据(列出食物交付)
{
int _childid,_菜单;
bool_交付状态;
for(int i=0;i
我做错了什么

请帮忙


谢谢

将tablebody渲染更改为razor syndax而不是Jquery,并为每个控件分配一个ID,以便更容易找到它的值

试试这个

var selectValMenuItem = $('.fordivdeliveryitemselector#' + chidltdid + ' :selected').val();                                        

var delvstatus = $('input[id=' + chidltdid+']').attr('checked');
var selectValMenuItem = $('.fordivdeliveryitemselector#' + chidltdid + ' :selected').val();                                        

var delvstatus = $('input[id=' + chidltdid+']').attr('checked');