我对mvc
有点新鲜我想为披萨订购网站创建一个订单表 该表从数据库填充,并且动态添加复选框 我想知道如何获取已选中复选框的ID并将其添加到列表
public int Ingredient_ID { get; set; }
public string dIngredient { get; set; }
public decimal dCost { get; set; }
public bool add { get; set; }
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">Choose ingredients</h2>
</div>
<table class="table">
<tr>
<th>
Ingredient
</th>
<th>
Cost
</th>
<th>
I want this
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.dIngredient)
</td>
<td>
@Html.DisplayFor(modelItem => item.dCost)
</td>
<td>
<!--add check box and submit-->
@Html.CheckBox(item.dIngredient, false, new { value = item.Ingredient_ID })
</td>
</tr>
}
</table>
<input type="submit" value="Createorder">Place order<input />
</div>
控制器如何工作?
答案 0 :(得分:0)
var myArray = new Array(3);
for ( var j = 0; j < 3; j++) {
var check=$('input:checkbox[name=checkbox'+j+']').is(':checked');
if(check==true)
myArray[j]=$('input:checkbox[name=checkbox'+j+']').val();
// Alert Current Selection //
alert('check ' + " " + myArray[j] );
}`
答案 1 :(得分:0)
var myArray = new Array(10);
for ( var j = 0; j < 10; j++) {
` var check=$('input:checkbox[name=checkbox'+j+']').is(':checked');`
if(check==true)
myArray[j]=$('input:checkbox[name=checkbox'+j+']').val();
// Alert Current Selection //
alert('check ' + " " + myArray[j] );
}
试试这可能会对你有所帮助