簡體   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