..NET MVC显示部分视图使用ajax.ActionLink无法正常工作

时间:2016-11-07 17:05:55

标签: asp.net ajax

我正在使用Ajax.ActionLink向我的action方法发送请求,并使用局部视图更新SelectedSTRMList div。但是,单击链接时,部分视图不会显示在div中。我可以在一个单独的窗口中查看局部视图。知道我做错了什么?在Chrome开发人员工具中,我在“网络”标签中检查了ajax请求,并且它正在返回请求。我还验证了我在ly布局视图中确实有ajax阻塞性js文件。感谢

查看

@model IEnumerable<NS.Models.FeeAuth>

<h2>Requests</h2>


<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>
            <th>
                @Html.LabelFor(m => m.First().fname)
            </th>
            <th>
                @Html.LabelFor(m => m.First().lname)
            </th
            <th></th>
        </tr>
        @{int i = 0;}
        @foreach (var item in Model)
        {

            <tr data-toggle="collapse" data-parent="#collapse1_@i" data-target="#collapse1_@i" class="accordion-toggle">
                <td>

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

                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.requestID)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.emplid)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.fname)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.lname)
                </td>                

            </tr>
            <tr>
                <td colspan="6" class="hiddenRow">
                    <div class="accordian-body collapse" id="collapse1_@i">
                        <div id="SelectedSTRMList">   
                        </div>
                    </div>
                </td>

            </tr>
            i++;
        }

    </table>

</div>

_Layout查看显示jquery

<script src="@Url.Content("~/Scripts/jquery-1.11.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.11.2.min.js")" type="text/javascript"></script>
    @*<script src="@Url.Content("//ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>*@
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

部分视图

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

         </ul>

     </td>
 </tr>         
</table>

控制器

 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 个答案:

没有答案