繁体   English   中英

ASP.NET MVC 渲染部分错误代码 CS0029

[英]ASP.NET MVC RenderPartial Error Code CS0029

不知道出了什么问题,但错误是“CS0029:无法将类型'void'隐式转换为'object'”在Html.Partial。另一篇文章说它应该用弯曲的括号括起来,但它仍然不起作用(与和没有)。 我试过 Html.RenderPartial 和 Html.Partial,两者都不起作用。

<div class="row" id="dtRecipe" style="margin-top:15px">
    @*@{ 
        Html.RenderPartial("_ListRecipe", new List<Eatery.Model.Models.Recipe>(), ViewData);
    }*@
    @Html.Partial("_ListRecipe", new List<Eatery.Model.Models.Recipe>(), ViewData);
</div>

_ListRecipe 的代码是
public async Task<ActionResult> _ListRecipe() { int DishID = Convert.ToInt32(ViewData["DishID"]); List<Recipe> recipes = (await recipeService.Get(DishID)).ToList(); return PartialView(recipes); }

recipeService 没问题,因为它在另一个文件中使用。

删除; 最后,它应该是(没有 razor 代码块语法):

 @Html.Partial("_ListRecipe", new List<Eatery.Model.Models.Recipe>(), ViewData)

如果你想正确使用Html.RenderPartial ,这是正确的语法类型(见下面的代码),这意味着你需要创建一个 razor 语法代码块,并且有一个; 在末尾:

@{
   Html.RenderPartial("_ListRecipe", new List<Eatery.Model.Models.Recipe>(), ViewData);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM