【发布时间】:2019-12-19 05:57:31
【问题描述】:
我有一个视图可以将数据库中的数据显示到数据表中。在表格中,我有编辑、删除和详细信息选项来执行这些相应的功能。
我的编辑和详细信息视图是不同的页面(视图)。 现在,当我单击第 2 行的编辑或删除时,它会将我带到该编辑/详细信息页面,但这些页面文本框中没有加载任何数据。
我的代码和设计如下:
加载数据表的代码:
function SearchCategory(){
$('#tblCategory').DataTable({
"processing": false,
"serverSide": false,
"searchable": false,
"ajax": {
url: '@Url.Action("GetValues")',
type: 'POST',
dataSrc: 'data',
},
"columns": [{ data: "CategoryId" },
{ data: "Description" },
{
"render": function (data, type, row) { return '<a class="text-center" href="/Master/CategoryDetails?id="' + row.CategoryId + '"><i class="fa fa-bars"></i></a>'; }
},
{
"render": function (data, type, row) { return '<a class="text-center" href="/Master/CategoryEdit?id="' + row.CategoryId + '"><i class="fa fa-edit"></i></a>'; }
},
{
data: null, render: function (data, type, row) {
return '<a href="#" class="text-center" onclick=DeleteData("' + row.CategoryId + '"); ><i class="fa fa-trash-o"></i></a>';
}
}]
});
}
}
餐桌设计:
<table cellspacing="1" cellpadding="2" style="width: 100%;" id="tblCategory" class="table table-striped table-hover table-bordered table-hd">
<thead>
<tr class="gridheader">
<td style="width: 30%;" class="search_field" search_field_value="CategoryId">Category Id</td>
<td style="width: 30%;" class="search_field" search_field_value="Description">Description</td>
<td style="width: 20%;" class="search_field" search_field_value="Details">Details</td>
<td style="width: 10%;" class="text-center">Edit</td>
<td style="width: 10%;" class="text-center">Delete</td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
我的桌子设计:
当我单击每一行中的编辑或详细信息图标时,它必须将我带到他们尊重的编辑/详细信息页面,它确实如此,但尊重的数据未加载到编辑/详细信息页面文本框中。
示例编辑页面设计:
每个详细信息和编辑页面都在不同的视图中:我在他们的脚本中尝试了类似以下的内容。
<script>
$(document).ready(function () {
$("#txtCategoryId").text = row.CategoryId;
$("#txtDescription").text = row.Description;
});
</script>
但它不工作如何做到这一点。还有如何删除选定的行?请帮助。TIA。
【问题讨论】:
-
text()是一个函数....但看起来你需要val(variable)才能获得<input> -
即使更改为 val() 也不起作用
-
控制台有错误吗?
row是如何定义的? -
没有出现错误,这让我很困惑,因为我是这个 MVC 的新手,因为没有错误,所以无法搜索输出
-
你能显示
Master控制器方法CategoryEdit你传递数据的地方吗
标签: javascript asp.net-mvc view datatable