I have a trouble when I try to pass values from razor to a javascript function. This works
<input type="button" value="Delete" onclick="deletePill()" />
function deletePill() {
console.log("Hola");
}
But when I do this it doesn't work
<input type="button" value="Delete" onclick="deletePill(@item.Id)" />" />
Or
<input type="button" value="Delete" onclick="deletePill()" data="@item.Id" />
function deletePill(Id) {
console.log(Id);
}
What should I change or add for it works?
I want passing values from Razor to javascript functions
The variables have values but it doesn't pass the values properly
CodePudding user response:
The variables have values but it doesn't pass the values properly. I want passing values from Razor to javascript functions.
Well, the way you are trying to pass value is incorrect. You ought to pass value using string literal because, while you are writing
Note: If you would like to know more details on it you could check our official document here