I essentially want to pass a multi-line string to a function from inside of a Razor/cshtml view.
I was hoping I could use <text>
to accomplish this.
Here's what I'm trying:
@Js.Tsc(@<text>
class Greeter {
greeting: string;
constructor (message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
var greeter = new Greeter("world");
var button = document.createElement('button')
button.innerText = "Say Hello"
button.onclick = function() {
alert(greeter.greet())
}
document.body.appendChild(button)
</text>.ToString())
But I still get
Compiler Error Message: CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type
on the @Js.Tsc(@<text>
line.
I thought the .ToString()
would have cast it properly. Is there a way to do this?
I know I can use @"
-style strings, but that makes writing the code in between more complicated.