页面局部视图:
Models.SeededCategories
@if (Model.Categories.Any(s => s.ParentId == Model.Seed))
{
<ul>
@foreach (var node in Model.Categories)
{
if (node.ParentId == Model.Seed)
{
var inner = new Models.SeededCategories {Seed = node.Id, Categories = Model.Categories};
<li>
@{if (inner.Categories.FirstOrDefault(p => p.ParentId == node.Id) != null)
{
<input type="checkbox" id="@node.Id"/><label><input type="checkbox" checked=@node.Check name="@node.ParentId" value="@node.Name"/><span></span></label><label for="@node.Id">@node.Name</label>
}
else
{
<input type="checkbox" id="@node.Id"/><label><input type="checkbox" checked=@node.Check name="@node.ParentId" value="@node.Name"/><span></span></label><span>@node.Name</span>
}
}
@Html.Partial("_TreeCategories", inner)
</li>
}
}
</ul>
}
并在视野中:
@model Tuple<Models.SeededCategories,Models.InsertNews>
@Html.Partial("_TreeCategories", Model.Item1,new ViewDataDictionary())
以下错误:
传入字典的模型项目为“SeededCategories&#39;”类型,但此字典需要“System.Tuple”2 [SeededCategories,InsertNews]类型的模型项
我在视图页面中有两个模型,因为使用两者请帮助我
答案 0 :(得分:0)
解决问题:
将代码插入Controller中的ActionResult:
var tuple = new Tuple<SeededCategories, InsertNews>(new SeededCategories { Seed = null, Categories = categories }, new InsertNews());
return View(tuple);