Should MVC4 PartialView ajax loading fire a “pageinit” event?

≯℡__Kan透↙ 提交于 2019-12-24 08:57:18

问题


In my asp.net mvc4 + jquerymobile app, I have a 'page' which looks something like this:

+---------------------------------------+
|A                                      |
|   +----------------+----------------+ |
|   |B               |C               | |
|   |                | +------------+ | |
|   |                | |D           | | |
|   |                | +------------+ | |
|   +----------------+----------------+ |
+---------------------------------------+
  • A is pretty much just a container page, it does nothing other than set up B & C 'subpages' (partial views)
  • B is a UserList panel(div), it has events bound which will cause and ajax reloading of panel C (a partial view)
  • C is a UserEdit panel(div), containing a secondary panel with other informations.
  • D is a UserPermissions panel(div), containing checkboxes to interact with the simplemembership roles system via ajax calls.

All four views I have some version of this script, to tell me which events are firing, when:

$(document).ready(function () {
    console && console.log("portalUser (pvUserEdit) document ready!!");
});
$(document).on('pageinit', function () {
    console && console.log("portalUser (pvUserEdit) pageInit!!");
});

When page A is first loaded, page B is loaded alongside, and both the pageinit event and the DOM ready event fire for both of them. When an item from the list in B is selected, it generates an ajax load to fill panel C (which causes panel D to also load). This time, only the DOM ready event fires for both C & D panels, never firing the pageinit event.

So, thats all the background info. The QUESTION is: is this the expected behavior, considering the MVC4+JQM aspect of the project? Should I expect pageinit to fire on partialView loads? Or do I need to handle the partial views differently than full pages?


回答1:


Javascript has no idea what kind of backend is running, so it's definitely not mvc issue. It may vary in different browsers but it's definitely differs because of ajax page loading



来源:https://stackoverflow.com/questions/15136983/should-mvc4-partialview-ajax-loading-fire-a-pageinit-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!