我有一个按钮:
a href='javascript:void(null)' onclick = "showDialog()" class='btn_history' id='@Model.contractFees.ElementAt(loop).FeeId' title='History'>History
这调用了这个脚本:
<script type ="text/javascript">
function showDialog() {
$("#history_dialog").dialog({
modal: true,
draggable: false,
resizable: false,
width: 600,
buttons: {
"Okay": function () {
$(this).dialog("close");
}
}
});
}
它使用这个div:
<div id='history_dialog' title="Contract Fee History" style="display: none">
<fieldset>
<input type="hidden" id="row_id" name="row_id" value="" />
<table id='historyOFee' width="100%" class="tan">
<thead>
<tr class="top">
<th>Effective Date</th>
<th>End Date</th>
<th>Fee %</th>
</tr>
</thead>
<tbody>
@foreach (ContractFee fee in Model.fullListOfFees.ToList())
{
<tr>
<td>
<text>@fee.EffectiveDate</text>
</td>
<td>
<text>@fee.EndDate</text>
</td>
<td>
<text>@fee.FeeRate</text>
</td>
</tr>
}
</tbody>
</table>
</fieldset>
我的问题是如何获取按钮 id 作为 div 中的值。
我真的需要这样做:
@foreach(ContractFee fee in Model.fullListOfFees.where(x =>x.ID == buttonId)
我尝试过将值传递到脚本、将值传递到模型和 ViewBag,但没有成功。
最佳答案
“我的问题是如何获取按钮 id 作为 div 中的值。”
使用 Ajax 进行异步调用并以 JSON 对象的形式返回所需的数据。为了在单击按钮时“刷新”div,您应该将其放在单独的部分 View 中,并在 AJAX 调用返回时成功时重新填充它。
关于javascript - 如何将数据传输到 ASP.NET MVC 中的 <div>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24164938/