2013-05-24 4 views
0

У меня проблема, с которой я застрял. У меня есть приложение MVC 3, и в этом приложении у меня есть концепции Survey and Training. Каждый тренинг имеет 1 обзор. Чтобы пользователи могли выполнять опрос, я открываю всплывающую страницу, когда щелкнула ссылку на действие HTML. Ниже приведен код для этого в DetailsSurvey.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> 

Тогда в стороне яваскрипта я следующие функции, чтобы открыть всплывающее окно:

$(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 подписаться на мероприятие, но он не работает. Это вызвано действием, предпринятым кнопкой закрытия, оно как-то теряет функциональность после закрытия. Есть ли какие-либо исправления?

ответ

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 
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(). Это будет работать. Благодарю.

+0

Это не открывается всплывающее окно, но заменяет мое все содержимое – Eneramo

+0

ли вы заменить «URL: this.href» с «URL: window.href» и «контекст: это» с «контекстом: окно» – Khalid

+0

я заменил но всплывающее окно не открывается, вместо этого оно заменяет мой контент – Eneramo