我一直在研究和尝试多次失败的尝试,以使用Ajax.actionlink在我的主视图中显示我的部分视图。使用开发人员工具并查看“网络”选项卡时,我确实看到了请求。单击预览时,我可以在局部视图中看到正确的数据。没有jQuery错误。
查看
@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="#collapse1_@i" data-target="#collapse1_@i" 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="collapse1_@i">
<div id="SelectedSTRMList_@i">
</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>
_Layout.cshtml中的Jquery
<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 :(得分:0)
您的更新目标是:
UpdateTargetId = "SelectedSTRMList" + i,
但你的div id是:
<div id="SelectedSTRMList_@i">
换句话说,您在更新目标字符串中缺少_
,或者您需要删除div ID中的_
。