Mar 26, 2014, 8:46 AM
[CLOSED] GridPanelFor in FormPanel does return values in Submit
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.
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(UserEvidenceDataViewModel 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;
}
Last edited by Daniil; Apr 03, 2014 at 4:08 AM.
Reason: [CLOSED]