Reputation: 21194
I want to achieve the following:
<input id="HtmlFieldPrefix_enterParentButton" type="button" value="Enter" />
I started off with:
<input id="@ViewData.TemplateInfo.HtmlFieldPrefix-enterParentButton" type="button" value="Enter"/>
which works perfectly, however, notice I used a dash instead of an underscore. If I switch to an underscore I receive an error: Razor thinks "_enterParentButton" is part of the C# code. How to stop the razor parsing before the underscore?
In other words, how to fix this line to behave as expected:
<input id="@ViewData.TemplateInfo.HtmlFieldPrefix_enterParentButton" type="button" value="Enter"/>
Upvotes: 1
Views: 401
Reputation: 18411
Embrace it with parenthesis:
@(ViewData.TemplateInfo.HtmlFieldPrefix)
<input id="@(ViewData.TemplateInfo.HtmlFieldPrefix)_enterParentButton" type="button" value="Enter"/>
Upvotes: 3