javascript - 如何将数据传输到 ASP.NET MVC 中的 <div>

标签 javascript html asp.net asp.net-mvc visual-studio-2010

我有一个按钮:

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/

相关文章:

javascript - (圆形)(类似 PowerPoint)在两个 div 之间转换

html - 如何使 HTML 复选框看起来像纸质表单复选框?

ASP.NET - 单击按钮时如何更改背景图像的位置?

c# - ASP.NET MVC 5 Identity with Model First

javascript - Libsodium JS KDF 函数产生不同的输出

仅在向上滚动时出现的返回顶部链接的 Javascript 语法帮助

javascript - jQuery为ajax请求返回 "parsererror"

javascript - 如何使用 phonegap 将数组值加载到 iPhone 应用程序中的 TableView 中

c# - ASP.NET C# 目标空白不适用于 LinkBut​​ton

javascript - Html字符串替换span的类在IE中不起作用?