繁体   English   中英

在MVC环境中的JQuery(UI)中仅使用“对话”功能帮助打开一个元素

[英]Help open only one element with “dialog” function in JQuery (UI) in MVC environment

大家好,如果我没有提供任何详细信息,请提前原谅,因为这是我的第一篇文章:

我在使用对话框JQuery命令时遇到问题。 更具体地说,我希望名为“编辑”的按钮(下面的第7行)仅打开1个窗口,而不是全部打开。 下面是我现在使用的一些代码,以及对编码发生的简短描述。 预先感谢您的阅读!

<!-- C# and HTML code here-->
<table> 
<tbody>
        <% foreach (var item in Model) { %>
    <tr>
    <td>    
                <button class="opener">Edit</button>
                <div class="dialogButton" title="Something"><% Html.RenderAction("Something", "Admin", new { id = item.ID }); %></div>
                 <td>Other values</td>
                  </tr>
</table>

<!-- JQ script is here-->
$(".dialogButton").dialog({ autoOpen: false });
            $(".dialogButton").dialog({ buttons: { "Ok": function () { $(this).dialog("close"); } } });
            $(".dialogButton").dialog({ show: 'fade' });
            $('.opener').click(function () { $('.dialogButton').dialog('open'); });

到目前为止,应用程序所做的是加载表格并在每行旁边都有一个编辑按钮(上面的第7行),但是,当按下“编辑”按钮时,Html.RenderAction(第8行)会为所有列表中的项目(item.ID),而不是仅选中的一行。 这意味着当前大约有25个窗口互相弹出。

我想要代码执行但到目前为止仍无法弄清的只是打开所选行的编辑窗口。

还建议用以下代码替换上面代码中的最后一行(第17行):

$('.opener').click(function () { $(this).next().dialog('open'); });

从理论上讲,这只是打开一个元素,但没有打开。 请帮忙!

再次感谢你!

只需为每个div class =“ dialogBu​​tton”和button class =“ opener”输入唯一的ID

例如div class =“ dialogBu​​tton” id =“ DialogBu​​tton_1”和button class =“ opener” id =“ opener_1。请使用item.ID或其他唯一的名称。

然后使用ID调用对话框插件

$('。opener')。click(function(){$('#dialogBu​​tton _'+ $(this).attr('id'))。dialog('open');});

基本上,您将以这种方式调用与打开程序对应的对话框

希望对您来说听起来合乎逻辑。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM