我尝试将视图模型参数传递给javascript函数。但是我发送了两个参数javascript函数不起作用。会发生什么情况?请回答我!!! 在HTML中
@if (Model != null)
{
int no =1;
for(int i =0; i<Model.purchaseOrderItemVMs.Count(); i++)
{
var count = i+1;
var ss = Model.purchaseOrderItemVMs[i].StockID;
<tr>
<td>
@no
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.purchaseOrderItemVMs[i].StockNo)
@Html.HiddenFor(modelItem => modelItem.purchaseOrderItemVMs[i].StockNo)
@Html.HiddenFor(modelItem => modelItem.purchaseOrderItemVMs[i].StockID, new { @id = "hidstockid" })
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.purchaseOrderItemVMs[i].Amount)
@Html.HiddenFor(modelItem => modelItem.purchaseOrderItemVMs[i].Amount)
</td>
<td>
<input type="button" class="btn btn-xs btn-primary" onclick="myFunction(@count,@ss)" value="Edit"/>
@Html.ActionLink("Remove", "Delete", new { id = Model.purchaseOrderItemVMs[i].StockID }, new { @class = "btn btn-xs btn-danger", @id = "btnDelete" })
</td>
</tr>
no++;
}
}
使用JavaScript
function myFunction(count, ss) {
alert(ss);
}
答案 0 :(得分:1)
替换inclickad的onclick函数语法:
<input type="button" class="btn btn-xs btn-primary" onclick="myFunction(@count,@ss)" value="Edit"/>
编写以下代码:
<input type="button" class="btn btn-xs btn-primary" onclick="myFunction('@count','@ss')" value="Edit"/>
应该可以