Displaying a literal period following razor syntax

荒凉一梦 提交于 2019-12-12 13:30:51

问题


How can I escape the razor engine to print a literal period after my property value? The compiler is interpreting the period as to be followed by a method or property, so it throws an error that 'PDF' is not a valid property or method.

col.Custom(@<a href="http://someurl/@item.INSTRUMENT_NUM.pdf">@item.INSTRUMENT_NUM</a>).Named("Instrument Number");

yellow screen of death

Compiler Error Message: CS1061: 'string' does not contain a definition for 'pdf' and no extension method 'pdf' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)


回答1:


Wrap it in parenthesis (assuming INSTRUMENT_NUM is a property of item and not to be printed as literal - adapt the closing parenthesis location if this is not the case):

col.Custom(@<a href="http://someurl/@(item.INSTRUMENT_NUM).pdf">@item.INSTRUMENT_NUM</a>)
   .Named("Instrument Number");


来源:https://stackoverflow.com/questions/16651584/displaying-a-literal-period-following-razor-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!