所有操作都在 View 中。
我的应用程序现在的样子:我从 websocket 服务器获取 JSON 数据并将其保存在某个 JS 变量中。
我想在我的 View 中创建此数据的动态内容表。我的想法是以某种方式(?)从 js 传递数据到 asp.net View ,并使用 for 循环创建该数据的表。
我应该尝试使用ajax吗?以及如何传递这些数据?
最佳答案
如果您只想从收到的 json 数据创建 TableView ,您可以使用 DataTables 插件,它是一个非常流行的 jQuery Javascript 库和高度灵活的工具,您将轻松获得许多附加功能,如排序、过滤。
这是一个您可以遵循的示例。
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "scripts/jsonp.php",
"dataType": "jsonp"
}
} );
} );
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
您将从源站获得更多有用的示例:DataTable
此外,如果您使用 AngularJS 或 KnockoutJS 等 JavaScript 框架,您还可以通过许多其他方式执行此操作。
关于javascript - 将数据从 JavaScript 传递到 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33519102/