How can I pass parameter from js to direct events Url Action?

290 views Asked by At

Is there a way to get objectId parameter from js and send it as parameter to Url action?

JS:

function ButtonClick(objectId) {
    App.testID.fireEvent("click", objectId);
}

Ext.net:

Html.X().ID("testID").DirectEvents
(
    de =>
    {
        de.Click.Url = Url.Action("TestMethod", "TestController");
        de.Click.ExtraParams.Add(new Parameter("objectId", "I need objectId here"));
    }
)
2

There are 2 answers

0
Aleksa Maksimovic On BEST ANSWER

I came with diferent solution when I saw compiled code in debugger. You can create direct event like this:

Html.X().ID("testID")
.Listeners
(
    l =>
    {
        l.AfterRender.Handler = @"App.testID.on('testEvent', function(id) {
                                                                             Ext.net.directRequest({
                                                                                url: '/TestController/TestMethod',
                                                                                extraParams:
                                                                                {
                                                                                    'objectId': id
                                                                                }
                                                                            });
                                                                        });";
    }
)

And fire it with:

function ButtonClick(objectId) {
    App.testID.fireEvent("testEvent", objectId);
}
0
Fabrício Murta On

Just add the raw code as the value string and add ParameterMode.Raw to the Parameter instance, like this:

de.Click.ExtraParams.Add(new Parameter("objectId", "App.MyComponent.Id", ParameterMode.Raw));

(based on Examples Explorer - Layouts > CardLayout)

Or alternatively, a custom object:

de.Click.ExtraParams.Add(new
{
    myTargetId = JRawValue.From("this.up('button').id")
});

(based on Examples Explorer - Models > Data Annotations)