2016-11-10 25 views
0

我一直在研究並嘗試多次失敗的嘗試,讓我的部分視圖在我的主視圖中使用Ajax.actionlink顯示。當使用開發人員工具並查看網絡選項卡時,我確實看到了請求。點擊預覽時,我可以在部分視圖中看到正確的數據。沒有jQuery錯誤。.NET MVC Ajax.ActionLink不返回部分視圖

查看

@model IEnumerable<NS.Models.FeeAuth> 

@using (Html.BeginForm()) 
{ 
<p> 
    <span class="glyphicon glyphicon-search"></span> Find by Last Name: @Html.TextBox("SearchString") 
    <input type="submit" value="Search" /> 
</p> 
} 

<div class="table-responsive"> 
    <table class="table table-condensed" style="border-collapse:collapse;"> 
     <tr> 
      <th> 
       @Html.LabelFor(m => m.First().ID) 
      </th> 
      <th> 

       @Html.ActionLink("Request ID", "ApprovalIndex", new { sortOrder = ViewBag.RequestIDSortParam }) 
      </th> 
      <th> 
       @Html.Label("emplid", "Student Emplid") 
      </th> 

     </tr> 
     @{int i = 0;} 
     @foreach (var item in Model) 
     { 

      <tr data-toggle="collapse" data-parent="#[email protected]" data-target="#[email protected]" class="accordion-toggle"> 
       <td> 

        @Ajax.ActionLink(Html.Encode(item.ID), 
      "SelectedSTRMS", 
      "FeeAuth", 
      new { id = item.ID, requestId = item.requestID }, 
new AjaxOptions 
{ 
    HttpMethod = "GET", 
    UpdateTargetId = "SelectedSTRMList" + i, 
    InsertionMode = InsertionMode.Replace 

}) 

      </td> 

       <td> 
        @Html.DisplayFor(modelItem => item.requestID) 
       </td> 
       <td> 
        @Html.DisplayFor(modelItem => item.emplid) 
       </td> 
      </tr> 
      <tr> 
       <td colspan="6" class="hiddenRow"> 
        <div class="accordion-body collapse" id="[email protected]"> 
         <div id="[email protected]"> 

         </div> 
        </div> 
       </td> 

      </tr> 
      i++; 
     } 
    </table> 
</div> 

管窺

<table> 

<tr> 
    <td> 
     <ul> 

       @foreach (var s in (List<string>)ViewBag.SemesterInfo) 
       { 
        <li style="padding-bottom:20px;">@s</li> 
       } 

     </ul> 

    </td> 
</tr>    

</table>  

的Jquery在_Layout.cshtml

<script src="~/Scripts/jquery-2.1.3.js" type="text/javascript"></script> 
<script src="~/Scripts/jquery-migrate-1.2.1.min.js" type="text/javascript"></script> 
<script src="~/Scripts/jquery.validate.js" type="text/javascript"></script> 
<script src="~/Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script> 
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script> 

控制器

[HttpGet] 
    public PartialViewResult SelectedSTRMS(int id, int requestId) 
    { 

     FeeAuthWithCommentsViewModel feeauth = new FeeAuthWithCommentsViewModel(); 
     feeauth.FeeAuth = db.FeeAuths.Find(id); 

     int feeauthID = id; 
     List<string> GetSTRM = new List<string>(); 

     GetSTRM = db.vw_GetSTRMs.Where(v => v.FeeAuthID == feeauthID).Select(v => v.DESCR).ToList(); 

     if (GetSTRM.Count > 0) 
     { 
      ViewBag.SemesterInfo = GetSTRM.ToList(); 
     } 
     else 
     { 

      ViewBag.SemesterInfo = new List<string> { "No STRM Selected" }; 
     } 

     return PartialView("_SelectedSTRMS"); 
    } 

回答

0

你的更新目標是:

UpdateTargetId = "SelectedSTRMList" + i, 

但你的div id爲:

<div id="[email protected]"> 

換句話說,你要麼缺少更新對象的_字符串或您需要刪除您的div id中的_

+0

哇。謝謝。我沒有明白。我浪費了這些日子。我將我的UpdateTargetId更改爲「SelectedSTRMList_」+ i – user2448412