简体   繁体   中英

MVC3 recursive partial view and Javascript file

Im having some problems with MVC3 and javascript

I have a structure with a view, contaning a partial view, contaning a partial view.

  • View
    • Partial view 1
      • partial view 2

In Partial view 1 I have a jquery datatable. Setup for this is in a Javascript file. This file is imported from partial view 1 and working fine.

When clicking a row in this table, i load partial view 2, with 3 jquery datatable. They are all setup within the same function as the "click" action for first table.

For these 3 new tables I need a button. I would like the function for this "click" action to be placed within the same Javascript file. But this is the problem. If i include the javascript directly in Partial view 2, the button click works.

If i include it within the javascript file, it dosent react to the click.

I have a suspetion that its a scope issue, but scripts loaded for partial view 1, is also accessable for partial view 2, right?

The click events for PV2 should be located in PV2, not PV1. Because when PV2 reloads and PV1 doesn't, the click events won't be recognised as the PV1 sees the buttons of PV2 as different ones.

EDIT: So I believe you are right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM