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

ASP.NET MVC Razor中三元表达式字符串渲染带引号问题排查

Fixing Unwanted Quotes in Razor Rendered Text

The issue here is that you’ve wrapped your Razor expression in literal double quotes inside the <h3> tag. Those quotes are being rendered as part of the text content, which is why you see them displayed on the page.

Immediate Fix

Remove the surrounding double quotes around your Razor expression. Here’s the corrected code:

<h3 class="panel-title">@(System.Configuration.ConfigurationManager.AppSettings["OST"] == "true" ? "Out-of-State Travel" : "Out-Service Training/Out-of-State Travel")</h3>

Cleaner, More Maintainable Approach (Optional)

For better readability and reusability, you can extract the logic into a Razor code block first:

@{
    // Retrieve the setting and determine the appropriate title
    var isOSTEnabled = System.Configuration.ConfigurationManager.AppSettings["OST"] == "true";
    var panelTitle = isOSTEnabled ? "Out-of-State Travel" : "Out-Service Training/Out-of-State Travel";
}

Then reference the variable directly in your HTML:

<h3 class="panel-title">@panelTitle</h3>

This makes your code easier to update later, especially if you need to reuse this title logic in multiple places or add additional conditions.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 08:25:56