【发布时间】:2021-09-18 14:16:29
【问题描述】:
我正在使用带有剃须刀页面的 ASP.Net 核心。
我有一个 html 表格,并使用 razor 语法循环这个 HTML 表格中的类对象,如下代码。
现在我想在循环表格时获取值,保存/用逗号连接通过循环分隔值并将其作为变量发送到 JavaScript 函数。此保存/连接并将其作为变量发送到 JavaScript 函数部分,我不知道该怎么做。任何帮助将不胜感激。
<div>
@if (Model.EmployeeDetails != null)
{
<table id="EmpDetail" class="table table-bordered">
<thead>
<tr>
<th style="width: 30%">Name</th>
<th style="width: 70%">Age</th>
</tr>
</thead>
<tbody>
@foreach (DTO.Employee emp in Model.EmployeeDetails)
{
<tr>
<td style="width: 30%">@emp.name</td>
// Here I need to concatenate with comma separation to a variable
and after the looping ends send to javascript function
<td style="width: 70%">@emp.age</td>
</tr>
}
</tbody>
</table>
}
</div>
<script type="text/javascript">jsFunctionCall("variableCommaSeperatedValues");</script> // here is the JavaScript
function call with paramter conatianing comma separated values from above
``````````
【问题讨论】:
标签: javascript html asp.net-core razor