我仅填写部分视图中需要的一些数据。我在用于部分视图的操作中填充模型,如下所示:
public PartialViewResult FetchCategoriesForHomePage()
{
CommonFunctions.CommonFunctions.APIParameters CategoryListAPiParameters = new CommonFunctions.CommonFunctions.APIParameters
{
fields = "*",
where = "enabled=true",
count = 1000
};
CommonFunctions.CacheHandling objCache = new CommonFunctions.CacheHandling(_cache);
dynamic categories = CommonFunctions.CommonFunctions.GetAsync(true, (int)(CommonFunctions.CommonFunctions.enumBullHornActionType.query), (int)(CommonFunctions.CommonFunctions.enumBullHornEntity.Category), objCache.GenerateBhRestToken(""), CategoryListAPiParameters).data;
List<CategoryEntity> listCategories = new List<CategoryEntity>();
foreach (var item in categories)
{
CommonFunctions.CommonFunctions.APIParameters SkillListForcategoryAPIParameters = new CommonFunctions.CommonFunctions.APIParameters
{
fields = "*",
where = "categories.id=" + item.id,
count = 1000
};
List<SkillSet> listSkills = new List<SkillSet>();
var Skills = CommonFunctions.CommonFunctions.GetAsync(true, (int)(CommonFunctions.CommonFunctions.enumBullHornActionType.query), (int)(CommonFunctions.CommonFunctions.enumBullHornEntity.Skill), objCache.GenerateBhRestToken(""), SkillListForcategoryAPIParameters).data;
foreach (var skillItem in Skills)
{
SkillSet skill = new SkillSet
{
id = skillItem.id,
name = skillItem.name
};
listSkills.Add(skill);
}
CategoryEntity category = new CategoryEntity
{
id = item.id,
name = item.name,
dateAdded = item.dateAdded,
Skills = listSkills
};
listCategories.Add(category);
}
return PartialView(listCategories);
}
在我看来,代码是:
@model List<Hallis.Entity.CategoryEntity>
<h2>Categories</h2>
<ul>
@foreach (var item in Model)
{
<li>
<strong> @item.name :</strong> @foreach (var skill in item.Skills)
{
<span>@skill.name,</span>
}
</li>
}
</ul>
我已经在另一个视图上调用了它,如下所示:
@await Component.InvokeAsync("FetchCategoriesForHomePage");
请纠正我我在做什么错。请帮我。