Uncaught ReferenceError: $ is not defined in Power BI Embedded












0















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?



enter image description here



enter image description here










share|improve this question























  • 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


















0















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?



enter image description here



enter image description here










share|improve this question























  • 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
















0












0








0








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?



enter image description here



enter image description here










share|improve this question














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?



enter image description here



enter image description here







javascript asp.net-core-mvc asp.net-core-2.0 powerbi-embedded






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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





















  • 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














1 Answer
1






active

oldest

votes


















0














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");






share|improve this answer
























  • 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











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
});


}
});














draft saved

draft discarded


















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









0














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");






share|improve this answer
























  • 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
















0














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");






share|improve this answer
























  • 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














0












0








0







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");






share|improve this answer













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");







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues