我有两个视图页面使用相同的控制器和模型作为更改页面布局的一种方式,但我无法显示我的第二页。这是我的错误信息:The parameters dictionary contains a null entry for parameter id of non-nullable type for method system.web.mvc.actionaresult ListView(int32) in UserController
不知道是什么导致了问题,除了只是更改视图布局外,我对第一个视图页面(工作)使用了相同的代码。
第一个视图
<div>
<a href="/Roster/ListView">Click Here for List view</a>
</div>
<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>
<a title="Email" id="emailIcon" class="icon-envelope icon-white" data-bind="attr:{'href':'mailto:' + Email()}"></a>
<a title="Profile" id="profileIcon" class="icon-user icon-white"></a>
</figcaption>
</figure>
<p data-bind="text:Name"></p>
</div>
</section>
</section>
列表显示
<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>
控制器
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.UserApiURL = "/api/User/" + id.ToString();
return View();
}
}
API 控制器
private UserService _userService = new UserService();
public IEnumerable<User> Get(int? id)
{
if (id.HasValue)
{
return _userService.GetUsers(id.Value);
}
throw new HttpResponseException(HttpStatusCode.NotFound);
}