我有问题。当他调用AssortmentController时," / assortment / kindlist?kindname = horror" 我收到错误:
传递到字典中的模型项是类型的 ' System.Collections.Generic.List`1 [Isf.Models.Movie]',但是这个 字典需要类型的模型项 ' Isf.ViewModels.HomeViewModel'
这是我的AssortmentController:
public class AssortmentController : Controller
{
AssortmentRelationships db = new AssortmentRelationships();
// GET: Assortment
public ActionResult Index()
{
return View();
}
public ActionResult ExplicationMovie(string moviename)
{
return View();
}
public ActionResult KindsList(string kindname)
{
var kinds = db.Kinds.Include("Movies").Where(k => k.KindName.ToUpper() == kindname.ToUpper()).Single();
var movies = kinds.Movies.ToList();
return View(movies);
}
[ChildActionOnly]
public ActionResult KindsMenu()
{
var kinds = db.Kinds.ToList();
return PartialView("_KindsMenu", kinds);
}
}
KindsList视图:
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-2" id="right-list">
@Html.Action("KindsMenu")
</div>
<div class="col-xs-12 col-md-10">
test
</div>
</div>
</div>
_KindsMenu查看:
@model IEnumerable<Isf.Models.Kind>
<ul>
@foreach (var kind in Model)
{
<li>
<a href="#">
<button class="btn btn-default" type="button">aaa</button>
</a>
</li>
}
</ul>
_MoviesList view:
@model Isf.Models.Movie
<div class="remove-all-margin-padding" id="category_view">
<img class="hover_detail" src="~/img/covers/1.jpg" />
</div>
PartialView没问题。如果我评论KindsList动作,一切都好 我不使用viewmodel,因为我在KindsList视图中使用html.action ... 我做过很多次,总是好的