asp.net-core - 在视图中的 Razor 表达式中编码双引号
问题描述
我在 ASP.NET Core Razor 视图上有以下表达式:
<a href="@(Options.CurrentValue.Applications.First(x => x.Name == "Spa").Url)">
当我构建它时,我得到了错误:
A space or line break was encountered after the "@" character. Only valid identifiers, keywords, comments, "(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.
我在 @ 之后添加了括号,因为我的代码中有双引号。
如何解决这个问题?
解决方案
当@ 之后存在空格、制表符(或任何特殊字符)时,我会遇到同样的错误。尝试使用 CTRL + E、S(在 VS 中)修改代码以显示所有特殊字符。
作为变体,您可以用单引号替换双引号:
<a href='@Options.CurrentValue.Applications.First(x => x.Name == "Spa").Url'>
推荐阅读
- firebase - SwiftUI:MacOS 上的 Firebase 登录
- java - 在java中将对象列表转换为地图
- visual-studio - 带有 Visual Studio 2022 的分析服务
- graph - 需要我的图形或条形图的表面图应该根据高度着色
- arrays - 函数 remove(atOffsets:) 仅在运行时抱怨错误类型
- python - Django:具有增量编号的自定义存储系统
- mongodb - 如何为以下查询编写 mongo 模板查询条件
- spring-websocket - 如何在 Spring Boot 测试中连接到安全的 Web 套接字端点
- php - 传递给 Illuminate\Auth\SessionGuard::login() 的 LARAVEL 7.0 参数 1 必须实现接口 Illuminate\Contracts\Auth\Authenticatable,给定数组
- javascript - 带有 IF 语句空检查的存储过程雪花