“class”是保留字,不能在隐式表达式中使用。必须使用显式表达式(“@()”)。 VS 22

问题描述 投票:0回答:1

Visual Studio 2022, 此代码导致剃刀视图出现异常:

object htmlAttr = null;
if (Model.ResourceInfo.Id > 0)
{
    htmlAttr = new {@class = "form-control", @readonly = "readonly", @disabled ="disabled"};
}
else
{
    htmlAttr = new { @class="form-control" };
}

html-helper visual-studio-2022
1个回答
1
投票

在@class为我工作之前添加“@”

htmlAttr = new {@@class = "form-control", @readonly = "readonly", @disabled ="disabled"};

浏览器:维瓦尔第 IDE:VS22

© www.soinside.com 2019 - 2024. All rights reserved.