[CLOSED] GridPanelFor in FormPanel does return values in Submit

  1. #1

    [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.

    // 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]
  2. #2
    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.
  3. #3
    Quote Originally Posted by Daniil View Post
    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?
  4. #4
    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.

Similar Threads

  1. [CLOSED] Formpanel Button: Disable auto submit
    By extnetuser in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 11, 2013, 4:57 PM
  2. How to Submit FormPanel Data
    By abhijit in forum 1.x Help
    Replies: 3
    Last Post: Feb 24, 2012, 7:18 AM
  3. Replies: 3
    Last Post: Mar 25, 2011, 9:55 AM
  4. Return values to Multicombo
    By flaviodamaia in forum 1.x Help
    Replies: 2
    Last Post: Jan 13, 2011, 9:49 AM
  5. [CLOSED] Submit FormPanel values via AjaxEvent
    By danielg in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Mar 12, 2009, 8:40 AM

Posting Permissions