I have a cshtml view file, which contains button, clicking on which will launch a function displayPopupWindow:
<button type="button" onClick="displayPopUpWindow(4);">Button Name</button>
Initially, all javascript code was located in the script
section of the same file. That way, everything is working the way it should be.
For debugging purposes, I have extended LoadVersionedJavascriptFile
functionality, so I can migrate the whole script section into a separate javascript file. I did so, while encasing entire script into $(function(){...})
Now, when I click the button, it throws the error that the function is undefined.
function displayPopUpWindow(reportType) {
//code
}
My main challenge is that even if I set a breakpoint on the first function line or just before the function, function is never accessed, so I cannot get any data, which could help me to figure out the cause.
Can anyone please point out why the function becomes unrecognized once the migration happens?
UPDATE:
I have applied all suggested changes, now the structure looks like the following
On the view page:
<div>
//code
<button type="button" id="btnDisplay" class="btn btn-primary">Display</button>
</div>
@section scripts {
@Html.LoadVersionedJavascriptFile("~/Scripts/Reports/ExpiringUnits.js")
}
On Javascript file:
$(function() {
$("btnDisplay").click(function () {
displayPopUpWindow(4);
});
function displayPopUpWindow(reportType) {
//code
}
});
However, it never hits a breakpoint inside click function. I can only assume that reportType value 4 is not rendered properly. What else is wrong?
UPDATE
Forgot #, feeling stupid =P