Uncaught ReferenceError: $ is not defined in Power BI Embedded
I'm trying to embed Power BI dashboard in my ASP.NET Core 2.1 Application. I get a javascript error while running this application saying $ is undefined. I have already defined this variable in a div and I'm trying to access this in the script. Here is my code for 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>
This is my Index.cshtml in my .net core 2.1 application. I get an error saying $ is undefined. I've clearly defined dashboardContainer. Why am I getting this error?
javascript asp.net-core-mvc asp.net-core-2.0 powerbi-embedded
add a comment |
I'm trying to embed Power BI dashboard in my ASP.NET Core 2.1 Application. I get a javascript error while running this application saying $ is undefined. I have already defined this variable in a div and I'm trying to access this in the script. Here is my code for 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>
This is my Index.cshtml in my .net core 2.1 application. I get an error saying $ is undefined. I've clearly defined dashboardContainer. Why am I getting this error?
javascript asp.net-core-mvc asp.net-core-2.0 powerbi-embedded
What does " I have already defined this variable in a div" mean?
– charlietfl
Nov 14 '18 at 16:50
This line var dashboardContainer = $('#dashboardContainer')[0]; is trying to get a reference to the embedded dashboard HTML element
– MAK
Nov 14 '18 at 16:55
Looks like you're attempting to use jQuery - have you checked that the jQuery script is included on the page, prior to this script?
– Robin Zigmond
Nov 14 '18 at 16:59
I'm including the layout _Layout.cshtml in my index. _Layout.cshtml includes jQuery script <script src="~/lib/jquery/dist/jquery.js"></script>
– MAK
Nov 14 '18 at 17:58
add a comment |
I'm trying to embed Power BI dashboard in my ASP.NET Core 2.1 Application. I get a javascript error while running this application saying $ is undefined. I have already defined this variable in a div and I'm trying to access this in the script. Here is my code for 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>
This is my Index.cshtml in my .net core 2.1 application. I get an error saying $ is undefined. I've clearly defined dashboardContainer. Why am I getting this error?
javascript asp.net-core-mvc asp.net-core-2.0 powerbi-embedded
I'm trying to embed Power BI dashboard in my ASP.NET Core 2.1 Application. I get a javascript error while running this application saying $ is undefined. I have already defined this variable in a div and I'm trying to access this in the script. Here is my code for 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>
This is my Index.cshtml in my .net core 2.1 application. I get an error saying $ is undefined. I've clearly defined dashboardContainer. Why am I getting this error?
javascript asp.net-core-mvc asp.net-core-2.0 powerbi-embedded
javascript asp.net-core-mvc asp.net-core-2.0 powerbi-embedded
asked Nov 14 '18 at 16:43
MAKMAK
444419
444419
What does " I have already defined this variable in a div" mean?
– charlietfl
Nov 14 '18 at 16:50
This line var dashboardContainer = $('#dashboardContainer')[0]; is trying to get a reference to the embedded dashboard HTML element
– MAK
Nov 14 '18 at 16:55
Looks like you're attempting to use jQuery - have you checked that the jQuery script is included on the page, prior to this script?
– Robin Zigmond
Nov 14 '18 at 16:59
I'm including the layout _Layout.cshtml in my index. _Layout.cshtml includes jQuery script <script src="~/lib/jquery/dist/jquery.js"></script>
– MAK
Nov 14 '18 at 17:58
add a comment |
What does " I have already defined this variable in a div" mean?
– charlietfl
Nov 14 '18 at 16:50
This line var dashboardContainer = $('#dashboardContainer')[0]; is trying to get a reference to the embedded dashboard HTML element
– MAK
Nov 14 '18 at 16:55
Looks like you're attempting to use jQuery - have you checked that the jQuery script is included on the page, prior to this script?
– Robin Zigmond
Nov 14 '18 at 16:59
I'm including the layout _Layout.cshtml in my index. _Layout.cshtml includes jQuery script <script src="~/lib/jquery/dist/jquery.js"></script>
– MAK
Nov 14 '18 at 17:58
What does " I have already defined this variable in a div" mean?
– charlietfl
Nov 14 '18 at 16:50
What does " I have already defined this variable in a div" mean?
– charlietfl
Nov 14 '18 at 16:50
This line var dashboardContainer = $('#dashboardContainer')[0]; is trying to get a reference to the embedded dashboard HTML element
– MAK
Nov 14 '18 at 16:55
This line var dashboardContainer = $('#dashboardContainer')[0]; is trying to get a reference to the embedded dashboard HTML element
– MAK
Nov 14 '18 at 16:55
Looks like you're attempting to use jQuery - have you checked that the jQuery script is included on the page, prior to this script?
– Robin Zigmond
Nov 14 '18 at 16:59
Looks like you're attempting to use jQuery - have you checked that the jQuery script is included on the page, prior to this script?
– Robin Zigmond
Nov 14 '18 at 16:59
I'm including the layout _Layout.cshtml in my index. _Layout.cshtml includes jQuery script <script src="~/lib/jquery/dist/jquery.js"></script>
– MAK
Nov 14 '18 at 17:58
I'm including the layout _Layout.cshtml in my index. _Layout.cshtml includes jQuery script <script src="~/lib/jquery/dist/jquery.js"></script>
– MAK
Nov 14 '18 at 17:58
add a comment |
1 Answer
1
active
oldest
votes
Seems like you need to include jquery. Try using classic javascript instead to see if that's the issue.
Replace
var dashboardContainer = $('#dashboardContainer')[0];
with
var dashboardContainer = document.getElementById("dashboardContainer");
Yes, I had done and it worked. I wanted to figure out why didn't $('#dashboardContainer')[0] work, since I'm including JQuery in _Layout.cshtml.
– MAK
Nov 15 '18 at 19:11
1
The order is important. JQuery include should be placed before your view's javascript content. Try using sections for your javascript and your styles in your Layout. @RenderSection("scripts", required: false), this inside your Layout. And then inside your pages : @section scripts{ <script src="~/js/Folder/myjavascriptFile.js" asp-append-version="true"></script> }
– Charly Guirao
Nov 16 '18 at 20:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305011%2funcaught-referenceerror-is-not-defined-in-power-bi-embedded%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Seems like you need to include jquery. Try using classic javascript instead to see if that's the issue.
Replace
var dashboardContainer = $('#dashboardContainer')[0];
with
var dashboardContainer = document.getElementById("dashboardContainer");
Yes, I had done and it worked. I wanted to figure out why didn't $('#dashboardContainer')[0] work, since I'm including JQuery in _Layout.cshtml.
– MAK
Nov 15 '18 at 19:11
1
The order is important. JQuery include should be placed before your view's javascript content. Try using sections for your javascript and your styles in your Layout. @RenderSection("scripts", required: false), this inside your Layout. And then inside your pages : @section scripts{ <script src="~/js/Folder/myjavascriptFile.js" asp-append-version="true"></script> }
– Charly Guirao
Nov 16 '18 at 20:19
add a comment |
Seems like you need to include jquery. Try using classic javascript instead to see if that's the issue.
Replace
var dashboardContainer = $('#dashboardContainer')[0];
with
var dashboardContainer = document.getElementById("dashboardContainer");
Yes, I had done and it worked. I wanted to figure out why didn't $('#dashboardContainer')[0] work, since I'm including JQuery in _Layout.cshtml.
– MAK
Nov 15 '18 at 19:11
1
The order is important. JQuery include should be placed before your view's javascript content. Try using sections for your javascript and your styles in your Layout. @RenderSection("scripts", required: false), this inside your Layout. And then inside your pages : @section scripts{ <script src="~/js/Folder/myjavascriptFile.js" asp-append-version="true"></script> }
– Charly Guirao
Nov 16 '18 at 20:19
add a comment |
Seems like you need to include jquery. Try using classic javascript instead to see if that's the issue.
Replace
var dashboardContainer = $('#dashboardContainer')[0];
with
var dashboardContainer = document.getElementById("dashboardContainer");
Seems like you need to include jquery. Try using classic javascript instead to see if that's the issue.
Replace
var dashboardContainer = $('#dashboardContainer')[0];
with
var dashboardContainer = document.getElementById("dashboardContainer");
answered Nov 15 '18 at 18:50
Charly GuiraoCharly Guirao
21123
21123
Yes, I had done and it worked. I wanted to figure out why didn't $('#dashboardContainer')[0] work, since I'm including JQuery in _Layout.cshtml.
– MAK
Nov 15 '18 at 19:11
1
The order is important. JQuery include should be placed before your view's javascript content. Try using sections for your javascript and your styles in your Layout. @RenderSection("scripts", required: false), this inside your Layout. And then inside your pages : @section scripts{ <script src="~/js/Folder/myjavascriptFile.js" asp-append-version="true"></script> }
– Charly Guirao
Nov 16 '18 at 20:19
add a comment |
Yes, I had done and it worked. I wanted to figure out why didn't $('#dashboardContainer')[0] work, since I'm including JQuery in _Layout.cshtml.
– MAK
Nov 15 '18 at 19:11
1
The order is important. JQuery include should be placed before your view's javascript content. Try using sections for your javascript and your styles in your Layout. @RenderSection("scripts", required: false), this inside your Layout. And then inside your pages : @section scripts{ <script src="~/js/Folder/myjavascriptFile.js" asp-append-version="true"></script> }
– Charly Guirao
Nov 16 '18 at 20:19
Yes, I had done and it worked. I wanted to figure out why didn't $('#dashboardContainer')[0] work, since I'm including JQuery in _Layout.cshtml.
– MAK
Nov 15 '18 at 19:11
Yes, I had done and it worked. I wanted to figure out why didn't $('#dashboardContainer')[0] work, since I'm including JQuery in _Layout.cshtml.
– MAK
Nov 15 '18 at 19:11
1
1
The order is important. JQuery include should be placed before your view's javascript content. Try using sections for your javascript and your styles in your Layout. @RenderSection("scripts", required: false), this inside your Layout. And then inside your pages : @section scripts{ <script src="~/js/Folder/myjavascriptFile.js" asp-append-version="true"></script> }
– Charly Guirao
Nov 16 '18 at 20:19
The order is important. JQuery include should be placed before your view's javascript content. Try using sections for your javascript and your styles in your Layout. @RenderSection("scripts", required: false), this inside your Layout. And then inside your pages : @section scripts{ <script src="~/js/Folder/myjavascriptFile.js" asp-append-version="true"></script> }
– Charly Guirao
Nov 16 '18 at 20:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305011%2funcaught-referenceerror-is-not-defined-in-power-bi-embedded%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What does " I have already defined this variable in a div" mean?
– charlietfl
Nov 14 '18 at 16:50
This line var dashboardContainer = $('#dashboardContainer')[0]; is trying to get a reference to the embedded dashboard HTML element
– MAK
Nov 14 '18 at 16:55
Looks like you're attempting to use jQuery - have you checked that the jQuery script is included on the page, prior to this script?
– Robin Zigmond
Nov 14 '18 at 16:59
I'm including the layout _Layout.cshtml in my index. _Layout.cshtml includes jQuery script <script src="~/lib/jquery/dist/jquery.js"></script>
– MAK
Nov 14 '18 at 17:58