Reputation: 18068
I want to display prompt for user to make easy for him to copy some text which would be concatenation of Model
properties.
If I do this:
function CopyToClipboard() {
window.prompt("Copy to clipboard: Ctrl+C, Enter", @Model.Id);
}
it works I get:
but If I want to pass property of type String
, like this:
function CopyToClipboard() {
window.prompt("Copy to clipboard: Ctrl+C, Enter", @Model.FirstName);
}
there is no prompt.
Upvotes: 1
Views: 109
Reputation: 56
Try
function CopyToClipboard() {
window.prompt("Copy to clipboard: Ctrl+C, Enter", '@Model.FirstName');
}
The javascript code has to be inside the html receiving the model.
Upvotes: 0
Reputation: 318352
The number 2 can be inserted without quotes, and is converted to a string automagically
function CopyToClipboard() {
window.prompt("Copy to clipboard: Ctrl+C, Enter", 2);
}
any other string would be a syntax error
function CopyToClipboard() {
window.prompt("Copy to clipboard: Ctrl+C, Enter", Yoda); // error
}
because it needs to be quoted
function CopyToClipboard() {
window.prompt("Copy to clipboard: Ctrl+C, Enter", "@Model.FirstName");
}
Upvotes: 2