我目前有一个查看页面,将用户列为带有他们的图像的画廊,但我还想创建一个按名称列出用户的查看页面。我想为他们两个使用一个控制器,我创建了一个ListView
页面,并在原始View
页面中按图像显示用户 - 我有一个查看ListView
页面的链接。我尝试单击链接,但页面未显示。这是我所拥有的:
图片查看页面
<h2>Users</h2>
<div>
<a href="~/Views/Users/ListView">Click Here for List view</a>
</div>
<section id="Images">
<section id="users" data-bind="foreach: Users">
<div id="nameImage">
<figure id="content">
<img width="158" height="158" alt="Gravatar" data-bind="attr:{src: GravatarUrl}"/>
<figcaption>
...
</figcaption>
</figure>
<p data-bind="text:Name"></p>
</div>
</section>
</section>
@section scripts{
@Scripts.Render("~/bundles/user" + ViewBag.Layout.AppVersionForUrls)
<script type="text/javascript">
(function ($) {
$.views.User.GetUser('@url');
})(jQuery);
</script>
}
列表视图页面
<div class="accordion-inner">
<div data-bind="foreach: Users">
<div>
<img width="158" height="158" alt="Gravatar" data-bind="attr:{src: GravatarUrl}"/>
<p data-bind="text:Name"></p>
</div>
</div>
@section scripts{
@Scripts.Render("~/bundles/user" + ViewBag.Layout.AppVersionForUrls)
<script type="text/javascript">
(function ($) {
$.views.User.GetUser('@url');
})(jQuery);
</script>
}
控制器
public ActionResult View(int id)
{
// get the menu from the cache, by Id
ViewBag.SideBarMenu = SideMenuManager.GetRootMenu(id);
ViewBag.UserApiURL = "/api/User/" + id.ToString();
return View();
}
public ActionResult ListView(int id)
{
// get the menu from the cache, by Id
ViewBag.SideBarMenu = SideMenuManager.GetRootMenu(id);
ViewBag.RosterApiURL = "/api/User/ListView" + id.ToString();
return View();
}