PDA

View Full Version : [CLOSED] GridPanelFor in FormPanel does return values in Submit



ATLAS
Mar 26, 2014, 8:46 AM
Hi guys,
In my MVC/Razor application, I have a window which has a FormPanel that includes a GridPanelFor where all fields are populated from a view model. The GridPanelFor is associated with a List of objects <UserMessage> and is rendered correctly. When I submit the form using a DirectEvent of a defined default "save" button, all fields including any that have been changed in the form are returned in the view model to the controller action .......... EXCEPT the list associated with the GridPanelFor. The list is returned empty. I'll give relevant code snippets.



// the view model
public class UserEvidenceDataViewModel
{
[Display(Name = "")]
public string UserId { get; set; }

[Display(Name = "")]
public string AwardId { get; set; }

[Display(Name = "")]
public string EvidenceFilename { get; set; }

[Display(Name = "")]
public string EvidenceType { get; set; }

[Display(Name = "")]
public string Description { get; set; }

[Display(Name = "")]
public string UserEnteredText { get; set; }

[Display(Name = "")]
public List<UserActivitiesDataViewModel> Activities { get; set; }

[Display(Name = "")]
public List<UserMessage> Messages { get; set; }
}


// the cshtml

@model UserEvidenceDataViewModel

@(Html.X().Window()
.ID("CREATE_EVIDENCE_WINDOW_ID")
.Layout(LayoutType.Fit)
.Icon(Icon.ApplicationFormEdit)
.Title(GlobalResources.CreateEvidence)
.Border(false)
.Resizable(true)
.Draggable(true)
.Width(600)
.Modal(true)
.AutoScroll(true)
.UI(UI.Info)

.Items(
Html.X().FormPanel()
.ID("CREATE_EVIDENCE_FORM_ID")
.DefaultButton("CREATE_EVIDENCE_SAVE_BUTTON_ID")

.Items(
Html.X().TextFieldFor(m => Model.UserId).ID("TEXTFIELDFOR_USERID_ID").Hidden(true),
Html.X().TextFieldFor(m => Model.EvidenceFilename).Hidden(true),
Html.X().GridPanelFor(m => Model.Messages),

Html.X().Panel()
.Border(true)
.Layout(LayoutType.HBox)
.LayoutConfig(new HBoxLayoutConfig { Align = HBoxAlign.StretchMax, Pack = BoxPack.Center })
.Height(40)
.Padding(5)
.Items( Html.X().Button()
.ID("CREATE_EVIDENCE_SAVE_BUTTON_ID")
.Icon(Icon.PageSave)
.Disabled(true)
.Text(GlobalResources.Save)
.DirectEvents(de => {
de.Click.Url = Url.Action("DirectEventCreateEvidence", "UserActivities");
de.Click.FormID = "CREATE_EVIDENCE_FORM_ID";
de.Click.EventMask.ShowMask = true;
de.Click.IsUpload = true;
de.Click.Before = @"if (!#{CREATE_EVIDENCE_FORM_ID}.getForm().isValid()) { return false; }";
de.Click.Success = "fnCreateEvidenceSuccess";
de.Click.Failure = "fnCreateEvidenceFailure";
}),

Html.X().Panel().BaseCls("x-plain").Width(50),

Html.X().Button()
.ID("CREATE_EVIDENCE_CANCEL_BUTTON_ID")
.Icon(Icon.PageCancel)
.Text(GlobalResources.Cancel)
.Listeners(ls => ls.Click.Fn = "fnWindowClose")
)
)
)
)


// the controller DirectEvent action

public FormPanelResult DirectEventCreateEvidence(UserEvidenceDataViewMode l info)
{
var result = WriteEvidenceFile(info);

// the operation has succeeded, fire off any prescribed User Messages
if (result.Success)
{
var loggedInUser = User as CustomPrincipal;

foreach (var userMsg in info.Messages)
{
_accountService.CreateUserMessage(userMsg, loggedInUser.UserId.ToString());
}
}
return result;
}

Daniil
Mar 26, 2014, 9:14 PM
Hi @ATLAS,

A FormPanel is supposed to be used with fields only (TextField, ComboBox, etc.). A GridPanel is not a field. Yes, you can put a GridPanel into a FormPanel, but the special FormPanel functionality like validation and submission won't work.

You should submit a GridPanel's data manually.

ATLAS
Mar 27, 2014, 7:52 AM
Hi @ATLAS,

A FormPanel is supposed to be used with fields only (TextField, ComboBox, etc.). A GridPanel is not a field. Yes, you can put a GridPanel into a FormPanel, but the special FormPanel functionality like validation and submission won't work.

You should submit a GridPanel's data manually.

Ok Daniil, is it possible to populate the model's list of objects returned via form submit using Click.Before event .... or what would you suggest?

Daniil
Mar 27, 2014, 4:30 PM
Yes, you can send a GridPanel's data as an extra parameter. You can add an extra parameter via a DirectEvent's Before handler or in a common way - via ExtraParams. In a controller action it should be deserialized to a Model instance as well.