我有菜单并使用此我在索引页面中呈现部分视图
@Ajax.ActionLink("week I", "firstWeekWinners", new
{
}, new AjaxOptions()
{
HttpMethod = "GET",
UpdateTargetId = "weeWinnersDIv",
InsertionMode = InsertionMode.Replace
}, new { @class = "weekDays wactive" })
以及那里的部分视图控制器:
public PartialViewResult firstWeekWinners()
{
ViewBag.laptopWinners = db.firstWeekLaptopWinner().ToList();
ViewBag.tabWinners = db.firstWeekGalaxyWinner().ToList();
ViewBag.ipodWinners = db.firstWeekIpodWinner().ToList();
ViewBag.headPhonesWinners = db.firstWeekHeadPhonesWinner().ToList();
ViewBag.kingstonWinners = db.firstWeekkingstonUsbWinner().ToList();
return PartialView();
}
和部分观点:
@if (ViewBag.laptopWinners != null)
{
<div class="winnersPrizeOverflow">
<div class="winnersPrizePic"></div>
<div class="winnersAllprizeLeft"><p>12</p></div>
</div>
foreach (var q in ViewBag.laptopWinners)
{
<span>@q.firstName</span>
<br />
<span>@q.lastName</span>
<br />
<span>@q.fbId</span>
<br />
<span>@q.sumOfBids</span>
<br />
}
}
如果我点击此 ajax.actionlink ,则会显示此视图,但如果我将@Html.Partial("firstWeekWinners")
放入{{1}},则不会显示此视图检索我的数据。
我该如何改进?
答案 0 :(得分:2)
要使用firstWeekWinners
方法拨打@Html.Action()
方法,而不是@Html.Partial()
@Html.Action("firstWeekWinners")
Refer to the documentation针对各种重载,以及这些question/answers解释差异和用法。