根据剃刀语法显示文字周期 [英] Displaying a literal period following razor syntax
问题描述
如何在我的属性值后转出剃须刀引擎以打印字面量?编译器正在解释该方法或属性后面的句点,因此会引发错误,即"PDF"不是有效的属性或方法.
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");
黄色的死亡画面
编译器错误消息:CS1061:字符串"不包含定义 表示"pdf",并且没有扩展方法"pdf"接受第一个自变量 可以找到字符串"类型(您是否缺少using指令或 程序集参考?)
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?)
推荐答案
将其括在括号中(假设INSTRUMENT_NUM
是item
的属性,并且不打印为文字-如果不是,请修改右括号的位置情况):
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");
这篇关于根据剃刀语法显示文字周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!