@Html.部分抛出CS1513:} expected错误
本文关键字:expected 错误 CS1513 @Html | 更新日期: 2023-09-27 18:04:22
我研究了关于CS1513: } expected
错误的多个其他问题,但没有一个有帮助。
我正在尝试在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>
}
<<p> 部分视图/strong> @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)