【问题标题】:How to add String with quotation in MVC model [duplicate]如何在MVC模型中添加带引号的字符串[重复]
【发布时间】:2020-08-19 06:25:24
【问题描述】:

我必须在 C# MVC 模型 (.cs) 文件中添加一个带有双 "Hide "My Account" Button" 的字符串。当我直接将它作为字符串添加时,它会引发错误。我在下面添加我的代码,请检查一下。

    [JsonProperty(PropertyName = "hidemyaccountbutton")]
    [Display(Name = "Hide "My Account" Button")]

【问题讨论】:

  • 不能使用单引号?

标签: c# asp.net .net asp.net-mvc visual-studio


【解决方案1】:

您可以像这样使用字符串逐字转义 C# 中的字符串:

[Display(Name = @"Hide ""My Account"" Button")]

或通过转义引号:

[Display(Name = "Hide \"My Account\" Button")]

【讨论】:

    【解决方案2】:

    您需要使用 \ 字符对引号进行转义。 示例:

    "The dog says \"Woof!\""
    

    【讨论】:

      猜你喜欢
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 1970-01-01
      • 2021-11-30
      • 2022-09-30
      • 2018-11-17
      • 2012-10-09
      相关资源
      最近更新 更多