【发布时间】:2014-01-29 16:00:53
【问题描述】:
我正在尝试使用 KendoGrid 内容模板和内联 Razor 动态设置单元格的内容,但我遇到了各种错误。
"<table><tr>" +
"<td style='color:yellow; width:200px;height:13px;padding-top:0px; margin-top:0px;text-align:center;' class='audiogrid'>" +
@{
@if ((int)TempData["MediaTypeId"] == 1) {
@"<audio id='a1' src='#: MediaLocation #' controls='controls' preload='auto' autobuffer><embed height='26' autostart = 'false' type = 'audio/mpeg' width='290' src='#: MediaLocation #'></audio>" +
}
else{
@" #: Description # " +
}
}
"</td>" +
"</tr></table>"
上面的代码抛出一个错误:CS1646: Keyword, identifier, or string expected after verbatim specifier: @ at the first instance of the @ sign.
我不明白这个错误的原因或含义。根据在 MVC4 中使用 Razor 的规则,我的语法应该可以工作。做了一些研究以确定并发现语法是准确的here 但我尝试了一个变体,在 @ 之后包含一个字符串,正如错误所建议的那样,我认为它应该也可以工作:
"<table><tr>" +
"<td style='color:yellow; width:200px;height:13px;padding-top:0px; margin-top:0px;text-align:center;' class='audiogrid'>" +
@if ((int)TempData["MediaTypeId"] == 1) {
@"<audio id='a1' src='#: MediaLocation #' controls='controls' preload='auto' autobuffer><embed height='26' autostart = 'false' type = 'audio/mpeg' width='290' src='#: MediaLocation #'></audio>" +
}
else{
@" #: Description # " +
}
"</td>" +
"</tr></table>"
这一次我收到编译器错误消息:CS1026:) 预期在 @ 首次出现在我的代码中的同一行。
我也尝试了一些其他的变体,但似乎都不起作用。 我在这里做错了什么或错过了什么? :-(
基本上单元格中的控件应该根据媒体类型而改变。
【问题讨论】:
标签: asp.net-mvc-4 razor