Search code examples
c#asp.net-mvcext.net

Indicate viewController Function for Client Side Event Handler


My goal is simple, all my Client side event handlers wish to be organised way in {View}Controller.js

In order to achieve the mention, I did following:

Indicate controller for view

     X.TreeList().ID("navTreeList")
                    .Config("controller", "navWindowController")                    
                    .Listeners(l=> { l.SelectionChange.Fn = "navTreeList_SelectionChange";  })

And declare function in the controller:

 navTreeList_SelectionChange : function (sender, event) {
    if (sender.getSelection().hasChildNodes())
        return false;
    // alert()
    return;

}

The good thing is that, init function of the controller is called but a navTreeList_SelectionChange event handler is not.

the reason: eventhendler not faund.

What should be done for the issue?


Solution

  • I found the solution- call the controller function as regular JS function by using Handler property of the SelectionChange listener instead of Fn

       X.TreeList().ID("navTreeList")
                            .Config("controller", "navWindowController")                    
                            .Listeners(l=> { l.SelectionChange.Handler = "#{navTreeList}.getController().navTreeList_SelectionChange";  })