I am trying to dynamically set the content of a cell using the KendoGrid Content Template and inline Razor but I am getting all sorts of errors.
"<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>"
The above code throws an error: CS1646: Keyword, identifier, or string expected after verbatim specifier: @ at the first instance of the @ sign.
I don't understand why or what this error means. According to the rules of using Razor in MVC4, my syntax should work. Did a little research to be sure and found the syntax to be accurate here But I tried a variation that included a string after the @ as the error suggested and that I figured should work as well:
"<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>"
This time I get Compiler Error Message: CS1026: ) expected at the same line that the @ first appears in my code.
I've also tried some other variations but none of them seem to work. What am I doing wrong or missing here? :-(
Basically the control in the cell should change based on the media type.