我正在嘗試創建一個表格標題,當點擊時提醒其文本。我無法將Razor變量傳遞給JavaScript函數參數。什麼是一個很好的解決方法?你如何獲得JavaScript來提醒Razor變量?
這裏是我的代碼:
@foreach (var web in Model.Webinars)
{
var title = web.Filename;
if (!String.IsNullOrEmpty(title))
{
// If filename is too long, shorten it
if (title.Length > 10)
{
title = title.Substring(0, 10) + "...";
}
// Create a header that alerts when clicked
// Errors if I pass @title in alert()
<th onclick="alert(@title)">@title</th>
}
}
我得到的是這樣的一個錯誤:
JavaScript critical error at line 71, column 34 in
http://localhost:64023/Webinar/Reports\n\nSCRIPT1010: Expected identifier
嘗試'