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>
_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");
}
ワウ。ありがとうございました。私はそれをキャッチしませんでした。私はこの日を無駄にしてしまった。 UpdateTargetIdを "SelectedSTRMList_" + iに変更しました – user2448412