@Html.Partial 抛出 CS1513:} 预期错误

@Html.Partial Throws CS1513: } expected Error

我研究了关于错误 CS1513: } expected 的其他多个问题,其中 none 有帮助。

我正在尝试向 C# MVC 5.2 中的视图引入分部视图。

我正在使用剃刀语法 @Html.Partial("MyPartialView") 并且也尝试过 @{ Html.RenderPartial("MyPartialView"); } 无济于事。

执行代码时,我在视图中收到错误,该错误包含在我尝试包含局部视图的行上的渲染助手。

如果我将局部视图粘贴到主视图中,则不会发生错误,这让我很困惑,因为绝对没有缺少大括号。

这是代码示例:

主视图

@model ProjectBagel.Models.BagelMania

@using(Html.BeginForm("SomeAction", "SomeController", FormMethod.Post))
{
    <fieldset>
        @Html.LabelFor(model => model.NormalBagel, new { @class = "control-label" })
        @Html.EditorFor(model => model.NormalBagel, new { htmlAttributes = new { @class = "form-control" }, })

        @Html.Partial("EvenTastierBagels") //Error here - MVC doesn't like a tastier bagels :-(

        @Html.LabelFor(model => model.LessTastierBagel, new { @class = "control-label" })
        @Html.EditorFor(model => model.LessTastierBagel, new { htmlAttributes = new { @class = "form-control" }, })

    </fieldset>
}

局部视图

@model ProjectBagel.Models.SuperAwesomeBagelMania

    @Html.LabelFor(model => model.SuperAwesomeBagel, new { @class = "control-label" })
    @Html.EditorFor(model => model.SuperAwesomeBagel, new { htmlAttributes = new { @class = "form-control" }, })

任何人都可以提出可能是什么问题吗?


免责声明:我既不出售也不认可百吉饼。

根据评论,我没有将视图模型传递给视图:

@Html.Partial("EvenTastierBagels", Model.BagelMania.SuperAwesomeBagelMania)