So I'm trying to pass a parameter to a javascript function using the razor '@' notation (in an MVC-4 View) but I'm getting Syntax error: "Unterminated string constant"
Is there another way I should be writing this?
@foreach (var item in Model) { ... <input type="button" value="Assign" onclick="AssignButtonClicked('@item.ID')" /> }
I've used the same syntax as this answer https://stackoverflow.com/a/5179316/1662619
Edit:
It's just a syntax error, the functionality still works
If you can use JQuery .data()
<input type="button" value="Assign" onclick="AssignButtonClicked(this)" data-assigned-id="@item.ID" />
Further it can be fetched using
function AssignButtonClicked(elem){ var id= $(elem).data('assigned-id'); }
try this
<input type="button" value="Assign" onclick="@("AssignButtonClicked('"+item.ID+"')")" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With