Today I spent a bunch of time trying to find out why a view with this script couldn't find the DoThis() method.
<script type="text/javascript">
$(document).ready(
function () {
alert("In the function about to call main.DoThis()");
DoThis();
});
</script>
Step 1) I used a layout for this view that had this render statement for a bundle we created.
@Scripts.Render("~/bundles/main")
The function DoThis was in a file named main.js contained in that bundle.
Step 2) I attempted to debug using Chrome's F12 function setting breakpoint on the script above and it kept saying that the script wasn't found when DoThis() was executed.
Step 3) I looked in the scripts folder from Chrome and the script I wanted was there...#?@?$
Being relatively new to Javascript and how browsers load it.... I never once figured the reason it wasn't found was because there were errors in the Javascript itself. The only indicator I had was a small red mark at the end of the JS file that indicated
I hadn't included a "}"... Wow! Good lesson I guess.
If you have this symptom better take a close look at the Javascript.
Yes and thanks for pointing that out. The editor also showed the issue but it was not a compiler error, rather it was a small red tick mark at the very bottom of the JavaScript page which was out of view from where I was working.
Member
137 Points
174 Posts
Calling a script from another file doesn't work. MVC @Scripts.Render and @RenderSection ....(solu...
Sep 23, 2014 04:56 PM|v2kea60|LINK
Today I spent a bunch of time trying to find out why a view with this script couldn't find the DoThis() method.
Step 1) I used a layout for this view that had this render statement for a bundle we created.
The function DoThis was in a file named main.js contained in that bundle.
Step 2) I attempted to debug using Chrome's F12 function setting breakpoint on the script above and it kept saying that the script wasn't found when DoThis() was executed.
Step 3) I looked in the scripts folder from Chrome and the script I wanted was there...#?@?$
Being relatively new to Javascript and how browsers load it.... I never once figured the reason it wasn't found was because there were errors in the Javascript itself. The only indicator I had was a small red mark at the end of the JS file that indicated I hadn't included a "}"... Wow! Good lesson I guess.
If you have this symptom better take a close look at the Javascript.
All-Star
120166 Points
27994 Posts
Moderator
MVP
Re: Calling a script from another file doesn't work. MVC @Scripts.Render and @RenderSection ....(...
Sep 23, 2014 05:15 PM|ignatandrei|LINK
if you look at the console, sure you will find a javascript error
Member
137 Points
174 Posts
Re: Calling a script from another file doesn't work. MVC @Scripts.Render and @RenderSection ....(...
Sep 25, 2014 09:19 AM|v2kea60|LINK
Yes and thanks for pointing that out. The editor also showed the issue but it was not a compiler error, rather it was a small red tick mark at the very bottom of the JavaScript page which was out of view from where I was working.
All-Star
120166 Points
27994 Posts
Moderator
MVP
Re: Calling a script from another file doesn't work. MVC @Scripts.Render and @RenderSection ....(...
Sep 25, 2014 07:55 PM|ignatandrei|LINK
I enabled in IE to display all javascript errors.