You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用dotnet build构建时如何修复@字符后空格/换行错误?

问题解决:"@字符后遇到空格或换行"编译错误

错误根源是Razor语法解析失败,你提供的代码片段中,@if(User.IsInRole("SupplyChainBuyer"))这一行未用大括号{}包裹后续的@Html.ActionLink代码块,且行尾存在多余换行和空格,导致Razor无法正确识别@符号后的代码结构。

修正后的代码:

@if(User.IsInRole("CFO") || User.IsInRole("Manager") || User.IsInRole("CEO") || User.IsInRole("Finance Manager") || User.IsInRole("IT-Line Manager") || User.IsInRole("IT-HOD")
    || User.IsInRole("SupplyChainBuyer") || User.IsInRole("SupplyChainManager"))
{
    <a asp-action="ApproveRequisition" asp-route-id="@Model.RequisitionId" class="fa fa-check" aria-hidden="true">Approve</a>
}|
@if(User.IsInRole("SupplyChainBuyer"))
{
    @Html.ActionLink("Automate RFQ", "IndexMethod", "RFQ", new { RequisitionNo = @Model.RequisitionNo }, null);
}|
@if (User.IsInRole("CFO") || User.IsInRole("Manager") || User.IsInRole("CEO") || User.IsInRole("Finance Manager") || User.IsInRole("IT-Line Manager") || User.IsInRole("IT-HOD"))
{
    <a asp-action="DeclineRequisition" asp-route-id="@Model.RequisitionId" class="fa fa-ban" aria-hidden="true">Decline</a>

}|
@if (User.IsInRole("Admin"))
{
    <a asp-action="Edit" asp-route-id="@Model.RequisitionId" class="fa fa-pencil-square-o">Edit</a>
}

关键修正点:

  • 给@if(User.IsInRole("SupplyChainBuyer"))补充了包裹代码块的{},让Razor能正确识别条件语句的范围
  • 清除了@if行尾多余的空行和空格,避免解析器误判@符号后的内容

内容的提问来源于stack exchange,提问作者Zidane

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 20:15:38