I'm trying to render one of my pages, and I have an Html.RenderAction()
call at the top of the div I'd like to display. I'd like to call one of my js initializer methods in document.ready()
from inside the page that is displayed via my RenderAction call, but it seems to be triggering document.ready()
before the html in the page after the Html.RenderAction()
call.
Because of this, the init function is checking data from a kendo element that hasn't loaded since it's being called before JQuery finishes up, and only sees the inputs that should be kendo inputs as default html <input>
elements.
In other words, is there a way to delay the loading / call of RenderAction until the page its inside of loads? Or should I just use some ugly CSS to keep the section I need at the top of my div? Very basic summary of my code below:
<html>
...
<div>
@Html.RenderAction("File that calls init() method")
<...rest of page that I need to load first, including kendo text boxes/>
</div>
</html>
File that calls init() method
<div>
...
</div>
<script src="...">
$(document).ready(function() {
myJs.init(params)
}
</script>
Now that I've gone to implement the answer below elsewhere, I've realized that when switching from document.ready
to window.on('load',...)
, it's now broken another view that works similarly, but instead the @Html.RenderAction
call is on the bottom:
...
<div>
<>page including kendo inputs</>
@Html.RenderAction("different file that calls same init() method")
</div>
</html>
Basically, document.ready
works for me if the razor is before the kendo, but not the other way around - and window.on('load',function(){...})
works for the opposite.
UPDATE: I ended up having to just rearrange my page after a lot of trial and error looking for a fix for this - seems like there's no easy way around the order in which the razor loads on CSHTML pages