我正在尝试在我的ASP.NET Core 2.1应用程序中嵌入Power BI dashboard。运行此应用程序时,我收到一个javascript错误,表示$未定义。我已经在div中定义了这个变量,我正试图在脚本中访问它。这是我的index.cshtml代码。
@model WebApplication2.Models.EmbedConfig
@{
ViewBag.Title = "Dashboard";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="https://npmcdn.com/es6-promise@3.2.1"></script>
<script src="~/js/powerbi.js"></script>
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
<div id="errorWrapper">
<h2>
Error
</h2>
@Model.ErrorMessage
</div>
return;
}
<br />
<a href="javascript:void(0);" class="btn btn-primary" id="backLink">Back</a>
<br /><br />
<h2>Embedded Dashboard</h2>
<br />
<div id="dashboardContainer"></div>
<script>
var accessToken = "@Model.EmbedToken.Token";
var embedUrl = "@Html.Raw(Model.EmbedUrl)";
var embedDashboardId = "@Model.Id";
var models = window['powerbi-client'].models;
var config = {
type: 'dashboard',
tokenType: models.TokenType.Embed,
accessToken: accessToken,
embedUrl: embedUrl,
id: embedDashboardId,
settings: {
background: models.BackgroundType.Transparent
}
};
// Get a reference to the embedded dashboard HTML element
var dashboardContainer = $('#dashboardContainer')[0];
// Embed the dashboard and display it within the div container.
var dashboard = powerbi.embed(dashboardContainer, config);
</script>
这是我的.NETCore2.1应用程序中的Index.cshtml。我得到一个错误,说$未定义。我已经清楚地定义了仪表板容器。为什么我会犯这个错误?