例如。
$(".button").click(function () {
var index=$(this).closest('tr').index();
var records=@Model.Task[index];
});
在此,index是javascript,@ Model.Task是服务器端,因此错误提示“名称索引在当前上下文中不存在”。
最佳答案
在点击功能之前,您应该执行以下操作。
var tasks = JSON.parse('@Html.Raw(Model.Task)');
之后,您可以做
$(".button").click(function () {
var index=$(this).closest('tr').index();
var records = tasks[index];
});