不是在頁面上顯示局部視圖,而是在新頁面上加載。這裏是我的代碼:MVC 3部分視圖不能正常工作
控制器:
public ViewResult Index()
{
ViewBag.Batch = 0;
return View();
}
public PartialViewResult ViewMore(int batch)
{
ViewBag.Batch = batch;
var artist = db.Artists.ToList().OrderBy(x => x.Name).Skip(10 * batch).Take(10);
return PartialView("_ViewMoreArtist", artist);
}
VIEW(指數)
@Ajax.ActionLink("View More...",
"ViewMore", new { batch = ViewBag.Batch + 1}, new AjaxOptions
{
UpdateTargetId = "viewMore",
InsertionMode = InsertionMode.InsertAfter,
HttpMethod = "GET"
//,LoadingElementId = "progress"
})
<div id="viewMore"></div>
視圖 - (_ViewMoreArtist) @model的IEnumerable
@foreach (var artist in Model)
{
@Html.ActionLink(artist.Name, "Browse", new { id = artist.ArtistId })
<br />
}
視圖 - (_layout)
<!DOCTYPE html> <html> <head>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript">/script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script> </head> <body>
<div id="main">
@RenderBody()
</div>
</body> </html>
注意:我已經在_Layout中添加了jquery.unobtrusive-ajax.js ...我在這裏要做的是使用示例MVCMusicStore項目,我添加了頁面以查看具有10個結果的藝術家以及一個選項查看更多結果...
你可以發佈你的_Layout視圖嗎? – gram
我現在修改了上面的代碼 – FlatCoder