简体   繁体   English

MVC3递归局部视图和Javascript文件

[英]MVC3 recursive partial view and Javascript file

Im having some problems with MVC3 and javascript 我在使用MVC3和javascript时遇到一些问题

I have a structure with a view, contaning a partial view, contaning a partial view. 我有一个带有视图的结构,包含一个局部视图,包含一个局部视图。

  • View 视图
    • Partial view 1 局部视图1
      • partial view 2 部分视图2

In Partial view 1 I have a jquery datatable. 在部分视图1中,我有一个jquery数据表。 Setup for this is in a Javascript file. 此设置在Javascript文件中。 This file is imported from partial view 1 and working fine. 该文件是从局部视图1导入的,并且工作正常。

When clicking a row in this table, i load partial view 2, with 3 jquery datatable. 当单击此表中的一行时,我加载具有3个jquery数据表的部分视图2。 They are all setup within the same function as the "click" action for first table. 它们都在与第一个表的“ click”操作相同的功能中设置。

For these 3 new tables I need a button. 对于这3个新表,我需要一个按钮。 I would like the function for this "click" action to be placed within the same Javascript file. 我希望将此“单击”操作的功能放在同一Javascript文件中。 But this is the problem. 但这是问题所在。 If i include the javascript directly in Partial view 2, the button click works. 如果我直接在部分视图2中包含javascript,则单击按钮即可。

If i include it within the javascript file, it dosent react to the click. 如果我将其包含在javascript文件中,它会对点击产生反应。

I have a suspetion that its a scope issue, but scripts loaded for partial view 1, is also accessable for partial view 2, right? 我怀疑这是一个范围问题,但是为部分视图1加载的脚本也可以为部分视图2访问,对吗?

The click events for PV2 should be located in PV2, not PV1. PV2的单击事件应位于PV2中,而不是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. 因为当PV2重新加载而PV1不重新加载时,单击事件将不会被识别,因为PV1将PV2的按钮视为不同的按钮。

EDIT: So I believe you are right. 编辑:所以我相信你是对的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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