PDA

View Full Version : [CLOSED] [RAZOR] Iterate over controls in FormPanel



gets_gui
May 09, 2012, 1:11 PM
Hi

I've defined the FormPanel outlined below. Within my controller given the reference to the FormPanel I want to iterate over the controls defined with the form.

I've tried the .Items, .Controls properties of the FormPanel but these properties don't seem to be initialised.

CSHTML Code:



Html.X().FormPanel()
.ID("formPanel")
.Title("formPanel")
.Collapsible(true)
.ButtonAlign(Alignment.Right)
.Layout(LayoutType.HBox)
.Items(items =>
{
items.Add(Html.X().Panel()
.ID("Panel1")
.Title("Panel1")
.Closable(true)
.CloseAction(CloseAction.Hide)
.Add(Html.X().DateField()
...
);

items.Add(Html.X().Panel()
.ID("Panel2")
.Title("Panel2")
.Closable(true)
.CloseAction(CloseAction.Hide)
.Add(Html.X().ComboBox()
...
);
...


Controller Code:



public ActionResult OnDirectClick()
{
var formControls = X.GetCmp<FormPanel>("formPanel").Items;

foreach(AbstractComponent control in formControls )
{
// Do operation
}

...
}

Vladimir
May 09, 2012, 2:20 PM
It is impossible:
- Controller's action doesn't know anything about view
- Razor doesn't operate by controls term (there are no any controls under Razor), therefore it is impossible ever inside Razor view
- X.GetCmp<> doesn't return real instance, it returns proxy object to manage client side properties (generate script for client side instance) and read submitted info