2013-05-28 77 views
0

我有一個頁面,其中列出了培訓以供員工對每項培訓進行調查。我在一個div中有多個彈出鏈接,點擊後會打開一個彈出窗口。以下腳本打開彈出窗口。我想在調查提交後更新彈出鏈接依賴新信息的部分,這意味着我只想列出他們的調查不被視爲彈出鏈接的調查。彈出關閉後刷新父div的內容MVC 3.0

$(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, 
         beforeClose: function (event, ui) { 
          reloadContent(); 
         } 

        }); //end of dialog 
       } //enf of success function 
      }); //end of ajax call 
      return false; 
     }); 
    }); 

要爲每一個訓練和上市我用下面的頁面彈出鏈接的鏈接。

@{if (Model.TrainingList == null || !Model.TrainingList.Any()) 
    { 
    <p> 
     Personel için anket bilgisi bulunamadı!</p> 
    } 
    else 
    { 

     foreach (var training in Model.TrainingList) 
     { 
    <table class="surveyTable"> 
     @{ if (training.Survey != null) 
      { 
      <tr> 
       <td class="view_detail_label"> 
        Eğitim Adı 
       </td> 
       <td> 
        @(training.Name != null ? @training.Name.Name : "") 
       </td> 
      </tr> 
      <tr> 
       <td class="view_detail_label"> 
        Eğitim İçeriği ve Programın Değerlendirilmesi Ortalaması 
       </td> 
       <td> 
        @((training.Survey.Context + training.Survey.Example 
       </td> 
      </tr> 

      <tr> 
       <td class="view_detail_label"> 
        Eğitimlerin Değerlendirilmesi 
       </td> 
       <td> 
        @((training.Survey.Knowledge)) 
       </td> 
      </tr> 

      <tr> 
       <td class="view_detail_label"> 
        Eğitim Materyallerinin ve Ortamının Değerlendirilmesi 
       </td> 
       <td> 
        @((training.Survey.Tool + training.Survey.Source) 
       </td> 
      </tr> 
      } 
      else 
      { 

      <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> 



      } 

     } 
    </table> 
    } 

     } 
    } 

以上頁的

<script type="text/javascript"> 
    $('#tab-container').easytabs(); 


</script> 
<div id="tab-container" class="tab-container"> 
    <ul class="etabs"> 
     <li class="tab"><a href="#employee_common">Genel Bilgiler</a></li> 
     <li class="tab"><a href="#employee_education">Eğitim Bilgileri</a></li> 
     <li class="tab"><a href="#employee_work">İş Tecrübesi</a></li> 
     <li class="tab"><a href="#employee_other">Kişisel</a></li> 

     <li class="tab"><a href="#employee_files">Dosyalar</a></li> 

     <li class="tab"><a href="#employee_turnike">Turnike</a></li> 
     <li class="tab"><a href="#employee_survey">Eğitim Anket</a></li> 


      <li class="tab"><a href="#employee_turnike_report">Kapı Giriş Raporu</a></li> 
      <li class="tab"><a href="#employee_training">Kurumsal Eğitimler</a></li> 
    </ul> 
    <div id="employee_common"> 
     @{ Html.RenderPartial("_DetailsCommon"); } 
    </div> 
    <div id="employee_education"> 
     @{ Html.RenderPartial("_DetailsEducation"); } 
    </div> 
    <div id="employee_work"> 
     @{ Html.RenderPartial("_DetailsWork"); } 
    </div> 

    <div id="employee_other"> 
     @{ Html.RenderPartial("_DetailsPersonal"); } 
    </div> 


     <div id="employee_survey"> 
      @{ Html.RenderPartial("_DetailsSurvey");} 
     </div> 

我在_DetailsS​​urvey.cshtml文件下面的腳本來只刷新DIV部分子頁面,但它不工作。

function reloadContent() { 
     $(document).load(window.location.href + " #employee_survey"); 
    } 

而另一個問題是,即使我刷新頁面將我的模型從控制器刷新呢?

+0

當你說「這是行不通的」,你的意思是你在控制檯中看到的錯誤,或根本沒有發生? –

+0

謝謝你的第一個答案。我沒有看到任何錯誤,沒有任何反應 – Eneramo

+0

「function reloadContent(){ location.reload(); }」當我這樣做刷新所有頁面,但我想刷新'employee_survey'div的鏈接div – Eneramo

回答

1

RE你最後一個問題:真的沒有,一旦視圖已經被渲染,所以沒有「模型」的概念。

拋出console.log('Closing');reloadContent()功能;這會告訴你方法是否被調用。如果您還沒有它,請確保您有Firebug或Firebug Lite(取決於您喜歡的瀏覽器進行調試)。

此:

function reloadContent() { 
    $(document).load(window.location.href + " #employee_survey"); 
} 

將無法​​正常工作。 load()需要一個CSS選擇器來加載內容; document是一個DOM元素。

編輯:讓我們嘗試利用一個擴展功能顯示在此回答另一個問題:https://stackoverflow.com/a/8452751/534109

添加擴展名(地方只是你$(document).ready()中):

$.fn.loadWith = function (url) { 
    this.load(url, function(response, status, jqxhr) { 
     $(this).children(':first').unwrap(); 
    }); 
}; 

reloadContent()說它:

function reloadContent() { 
    $('#employee_survey').loadWith (window.location.href + " #employee_survey"); 
} 

unwrap()如果你想知道發生了什麼。

+0

的reloadContent功能刷新格但會刪除所有它裏面 – Eneramo

+0

@Eneramo假設你有螢火蟲或類似的,什麼是調用'負載()'當你得到的迴應?在Firebug中,您可以擴展響應,並且會出現一個標籤,顯示返回的標記(如果有)。 –

+0

http:// localhost:50735 /?_ = 1369729856526作爲鏈接返回,並作爲響應返回所有內容 – Eneramo