0

我有一个问题,我被困住了。我有 MVC 3 应用程序,在这个应用程序中我有调查和培训的概念。每个培训有 1 个调查。为了让用户参加调查,我在单击 HTML 操作链接时打开了一个弹出页面。下面是 DetailsS​​urvey.cshtml 中的代码:

  <tr>  <td class="view_detail_label">
                Eğitim Adı
            </td>
            <td>                    
               @Html.ActionLink(
               training.Name.Name, 
               "AddSurvey", 
               new { 
                   employeeId = Model.Id, 
                   trainingId = training.Id 
               },
               new {
                   @class = "addSurvey"
               }
           )
             <div class="result" style="display:none;"></div>
            </td>               
        </tr> 

然后在javascript方面我有以下功能来打开弹出窗口:

$(document).ready(function () {
    $('.addSurvey').click(function () {
        $.ajax({
            url: this.href,
            type: 'GET',
            cache: false,
            context: this,
            success: function (result) {
                $(this).next('.result').html(result).dialog({
                    autoOpen: true,
                    title: 'Anket',
                    width: 500,
                    height: 'auto',
                    modal: true
                }); //end of dialog
            } //enf of success function
        }); //end of ajax call
        return false;
    });

});

$(document).delegate('.addSurvey', 'click', function () {
    $.ajax({
        url: this.href,
        type: 'GET',
        cache: false,
        context: this,
        success: function (result) {
            $(this).next('.result').html(result).dialog({
                autoOpen: false,
                title: 'Anket',
                width: 500,
                height: 'auto',
                modal: true
            }); //end of dialog
        } //enf of success function
    }); //end of ajax call
});

可以有 1 个或多个调查链接。发生的情况是,当我单击按钮时,弹出窗口第一次打开,但是当我关闭弹出窗口并尝试重新打开它时,它根本没有打开。如果我在新选项卡或窗口中打开它,它会分别打开。我使用delegate了订阅事件,但它不起作用。这是由关闭按钮采取的操作引起的,它在关闭后不知何故失去了功能。有什么修复吗?

4

2 回答 2

0
<tr>  <td class="view_detail_label">
            Eğitim Adı
        </td>
        <td>                    
           @Html.ActionLink(
           training.Name.Name, 
           "AddSurvey", 
           new { 
               employeeId = Model.Id, 
               trainingId = training.Id 
           },
           new {
               @class = "addSurvey"
               @onclick="javascript:OpenSurveyPopup();"
           }
       )
         <div class="result" style="display:none;"></div>
        </td>               
    </tr> 
<script type="text/javascript">
    function OpenSurveyPopup()
 {
    $.ajax({
        url: this.href,
        type: 'GET',
        cache: false,
        context: this,
        success: function (result) {
            $(this).next('.result').html(result).dialog({
                autoOpen: true,
                title: 'Anket',
                width: 500,
                height: 'auto',
                modal: true
            }); //end of dialog
        } //enf of success function
    }); //end of ajax call
    return false;
});
 }
</script>

同时删除 $(document).ready() 和 $(document).delegate()。这将起作用。谢谢。

于 2013-05-24T10:03:23.667 回答
0

我使用以下实时功能解决了问题,我所做的是:在弹出窗口的关闭操作中,我调用了我的控制器并重新渲染页面,现在它就像一个魅力一样工作。

$('a.addSurvey').live('click', function (e) {
        var $this = $(this);
        e.preventDefault();
        $.ajax({
            url: this.href,
            type: 'GET',
            cache: false,
            context: this,
            success: function (result) {
                $(this).next('.result').html(result).dialog({
                    autoOpen: true,
                    title: 'Anket',
                    width: 500,
                    height: 'auto',
                    modal: true,
                    close: function () { console.log("onClose"); $('.surveyTable').load('Home/DetailsSurvey', {id:@Model.Id}); }
                }); //end of dialog
                console.log($(this).next('.result'));
            }, //enf of success function
            complete: function () {
                console.log("Complete");
            },
            error: function () {
                console.log("Error");
            }
        }); //end of ajax call
    });   //end of live
于 2013-05-30T08:16:05.930 回答