Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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# 停止属性内的内联代码块_C#_Asp.net Mvc_Asp.net Mvc 4_Razor - Fatal编程技术网

C# 停止属性内的内联代码块

C# 停止属性内的内联代码块,c#,asp.net-mvc,asp.net-mvc-4,razor,C#,Asp.net Mvc,Asp.net Mvc 4,Razor,我希望实现以下目标: <input id="HtmlFieldPrefix_enterParentButton" type="button" value="Enter" /> 我从以下几点开始: <input id="@ViewData.TemplateInfo.HtmlFieldPrefix-enterParentButton" type="button" value="Enter"/> 但是,请注意,我使用了破折号而不是下划线。如果我切换到下划线,我会收到

我希望实现以下目标:

<input id="HtmlFieldPrefix_enterParentButton" type="button" value="Enter" />

我从以下几点开始:

<input id="@ViewData.TemplateInfo.HtmlFieldPrefix-enterParentButton" type="button" value="Enter"/>

但是,请注意,我使用了破折号而不是下划线。如果我切换到下划线,我会收到一个错误:Razor认为“_enterproentbutton”是C代码的一部分。如何在下划线之前停止razor解析

换句话说,如何修复该行以使其按预期运行:

<input id="@ViewData.TemplateInfo.HtmlFieldPrefix_enterParentButton" type="button" value="Enter"/>

用括号括起来:

@(ViewData.TemplateInfo.HtmlFieldPrefix)


<input id="@(ViewData.TemplateInfo.HtmlFieldPrefix)_enterParentButton" type="button" value="Enter"/>
@(ViewData.TemplateInfo.HtmlFieldPrefix)

就这么简单,谢谢!只要SO允许,我会尽快标记为已回答:-)是的,是的……我也曾去过那里,我知道当你试图实现某件事,但却犯了恼人的错误时,是多么令人沮丧。。。。