使用参数打开jQuery对话框 [英] Open jQuery dialog with a parameter

查看:63
本文介绍了使用参数打开jQuery对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC视图,我想从中弹出jQuery对话框.在对话框中,我想呈现一个视图,但是控制器操作需要一个参数.这就是我所拥有的:

I have an MVC view from which I want to popup a jQuery dialog. In the dialog, I want to render a view, but the controller action requires a parameter. Here's what I have:

$(document).ready(function () {
            $dialog = $('<div></div>')
            .dialog({
            open: function(event, ui) {
                $(this).load("@Url.Action("Edit", "Agenda", new {id = ???})"); //Line to fix
            },
            autoOpen: false
        });

再往下,我有这段代码调用对话框.请注意,我要传递给控制器​​操作的idcalEvent.id

And further down, I have this code calling the dialog. Note that the id I want to pass to the controller action is calEvent.id

$('#calendar').fullCalendar({
    eventClick: function (calEvent, jsEvent, view) {
        $dialog.dialog('open');
    }
});

所以问题是:如何修改我的代码以将calEvent传递给id参数?

So the question is: How can I adapt my code to pass calEvent to the id parameter?

推荐答案

jQuery提供了一种为您存储数据的方法,无需使用虚拟属性或找到解决问题的方法.

jQuery provides a method which store data for you, no need to use a dummy attribute or to find workaround to your problem.

使用jquery对话框对象上的.data()方法在调用对话框时将所需的任何数据绑定到对话框,并使用open()函数中的相同方法将其读出:

use the .data() method on the jquery dialog object to bind any data you want to your dialog when calling it, and the same method within the open() function to read it out:

$('#calendar').fullCalendar({
eventClick: function (calEvent, jsEvent, view) {
    $dialog.data('id', calEvent.id).dialog('open');
}
});

$(document).ready(function () {
        $dialog = $('<div></div>')
        .dialog({
        open: function(event, ui) {
            url = "@Url.Action("Edit", "Agenda", new {id = "XXX"})";
            url.replace( "XXX", $(this).data('id') );
            $(this).load(url);
        },
        autoOpen: false
    });

这篇关于使用参数打开jQuery对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆