有没有办法在 JavaScript 代码块中设置 razor @HTML.Hidden 控件值?
<tbody>
@Html.Hidden("customerID")
@if (Model != null)
{
var customers = Model.Customers.ToList();
for (var i = 0; i < customers.Count; i++)
{
<tr class="gradeX">
<td>
<a href="#"><span onclick="GetCustomerID()">@customers[i].CustomerId.ToString()</span></a>
</td>
<td>
<a href="#">@customers[i].Name</a>
</td>
</tr>
}
}
</tbody>
我的 JavaScript 块是
<script type="text/javascript">
var globleCustomerId = null;
function GetCustomerID() {
globleCustomerId = $('#customerID').val();
//globleCustomerId value should be set to @Html.Hidden()
}
</script>
在这个 JavaScript 块中,我需要将 globleCustomerId 值设置为 @Html.Hidden("customerID")。
如何获得该值?