PDA

View Full Version : [CLOSED] [Razor] Parameter passing from DirectEvents



gets_gui
Apr 18, 2012, 1:02 PM
Hi

I've created a combobox with a directEvent attached and defined the method in the controller which is called when the user selected a value.

What is the best way to either:

1) Pass the selected value into the Controller
2) Access the selected value directly from Controller

cshtml



@(
Html.X().ComboBox()
.ID("cbDirectEvent")
.Text("ComboBox1")
.Store(store => store.Add(
...
))
.Model(model => model.Add(Html.X().Model()
.Fields(fields =>
{
fields.Add(Html.X().ModelField().Name("Value"));
})
))
))
.DirectEvents(directEvents =>
{
directEvents.Select.Url = "/Controller/ValueSelect";
})
.DisplayField("Value")
.ValueField("Value")
)


Controller Code



public ActionResult ComboBoxSelect()
{
// Use selected value from combobox
}

Daniil
Apr 18, 2012, 6:45 PM
Hi,

The best way would be sent a value via ExtraParams.

Example

@(Html.X().ComboBox()
.DirectEvents(directEvents => {
directEvents.Select.Url = "Test/ComboBoxSelect";
directEvents.Select.ExtraParams.Add(new Ext.Net.Parameter()
{
Name="value",
Value="record.get(this.valueField)",
Mode = ParameterMode.Raw
});
})
)


public ActionResult ComboBoxSelect(string value)

gets_gui
Apr 24, 2012, 5:29 PM
Thanks for the reply Daniil

I've got another related question. Is it possible to access other component values when passing parameters (2nd ExtraParam block)


.DirectEvents(directEvents =>
{
directEvents.Select.Url = "/Shared/ComboBoxSelect";
directEvents.Select.ExtraParams.Add(new Parameter()
{
Name = "parameter1",
Value = "item.value",
Mode = ParameterMode.Raw
});
directEvents.Select.ExtraParams.Add(new Parameter()
{
Name = "parameter2",
Value = "document.getElementById('componentID').value",
Mode = ParameterMode.Raw
});
})

Daniil
Apr 24, 2012, 5:32 PM
Please wrap the code in [CODE ] tags. It will improve its readability.

Daniil
Apr 24, 2012, 5:44 PM
Thanks for editing.

This doesn't allow to access Ext.NET widgets.

document.getElementById('componentID')

You can access Ext.NET widgets directly by its client ids.

Example

Value = "App.componentID.getValue()"