【发布时间】:2021-04-01 21:10:49
【问题描述】:
我的观点如下
@{
foreach (var book in @Books)
{
<tbody>
<tr>
<th scope="row">@book.Title</th>
<th scope="row">@book.Author</th>
<th scope="row">
<button onclick="favouriteBook(@book.Id)">Favourite</button>
</th>
</tr>
</tbody>
}
}
还有一个单独文件中的 JavaScript 函数(正如我使用 console.log 测试过的那样,该函数已正确加载:
function favouriteBook(id) {
localStorage.setItem("bookId", id);
// Later to be a DB, just testing for now.
}
但是当用户点击按钮调用这个函数时,我得到一个Uncaught SyntaxError: Invalid or unexpected token error.这里有什么问题?
【问题讨论】:
标签: javascript c# asp.net-mvc