Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Razor字符串变量用作html表th或td标题值_C#_Html_Variables_Razor_Title - Fatal编程技术网

C# Razor字符串变量用作html表th或td标题值

C# Razor字符串变量用作html表th或td标题值,c#,html,variables,razor,title,C#,Html,Variables,Razor,Title,在*.cshtml文件中 @{ var tooltip = "Once a day"; } <table> <tr> <th title=@tooltip>A</th> <th title="Once a day">B</th> </tr> </table> @{ var tooltip=“每天一次”; } A. B 第一个单元格仅显示“一次”,但第二个单元格正确显示“一天一次”。

在*.cshtml文件中

@{
var tooltip = "Once a day";
}
<table>
<tr>
    <th title=@tooltip>A</th>
    <th title="Once a day">B</th>
</tr>
</table>
@{
var tooltip=“每天一次”;
}
A.
B
第一个单元格仅显示“一次”,但第二个单元格正确显示“一天一次”。
我想在很多地方使用相同的变量。如何解决此问题?

您需要在
@tooltip
周围加上引号,您应该查看生成的HTML是否正确

我怀疑它看起来会像

<table>
<tr>
    <th title=Once a day>A</th>
    <th title="Once a day">B</th>
</tr>
</table>

A.
B

您需要在
@tooltip
周围加上引号,您应该查看生成的HTML是否正确

我怀疑它看起来会像

<table>
<tr>
    <th title=Once a day>A</th>
    <th title="Once a day">B</th>
</tr>
</table>

A.
B

@Daebarkee你能按回答做吗?@Daebarkee你能按回答做吗?