Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Novian Winangun 1 post 72 karma points
    Oct 20, 2015 @ 23:27
    Novian Winangun
    0

    Client Side populated data was lost when returning to current umbraco page. CurrentUmbracoPage().

    Hi,

    I am developing a form using umbraco 7.2.4 and SurfaceController.

    I have 3 list boxes defined in the view as follows:

    @Html.ListBoxFor(m => m.occsectors, new SelectList(Model.occsectorList, "Value", "Text", Model.occsectors), new { @Id = "OccSectorsList", size = 8 })

    @Html.ListBoxFor(m => m.occgroups, new SelectList(Model.occgroupList, "Value", "Text", Model.occgroups), new { @Id = "OccGroupList", size = 8 })

    @Html.ListBoxFor(m => m.occupations, new SelectList(Model.occupationList, "Value", "Text", Model.occupations), new { @Id = "OccList", size = 8 })

    The first list box "OccSectorsList" is populated in the controller by populating Model.occsectors

    But the other two are populated on the client side using Ajax function and jQuery to populate the list box.

    All working except when the model is invalid and returning to the form using CurrentUmbracoPage() from controller. The data of "OccGroupList" and "OccList" are lost. But, the first list box "OccSectorsList" retains its list and selected value.

    Anyone has any clue how to solve this?

  • Bo Jacobsen 606 posts 2404 karma points
    Jul 05, 2016 @ 09:41
    Bo Jacobsen
    0

    Any updates on this?

    We got the same problem. If we populate a list inside the model in the view with JQuery. We would get the data in the SurfaceController. But loose it again if the model is not valid.

    For the exsample we populated 2 items in the list.

    @using (Html.BeginUmbracoForm<MemberController>("Submit"))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
    
        @* The list contains zero submembers. (But it could) *@
        @for (var i = 0; i < Model.SubMembers.Count; i++)
        {
            @Html.TextBoxFor(model => model.SubMembers[i].Name)
        }
    
        @* So we populate 2 here *@
        <input id="SubMembers_0__Name" name="SubMembers[0].Name" type="text" value="Jens">
        <input id="SubMembers_1__Name" name="SubMembers[1].Name" type="text" value="Per">
    }
    

    In the SurfaceController we would get these 2 populated submembers,

     [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Submit(MemberModel model)
        {
            // Contains 2. Contains Jens & Per
            var listCount = model.SubMembers.Count;
    
            if (!ModelState.IsValid)
            {
                // if the model is invalid. We loose the model.SubMembers in the view.
                return CurrentUmbracoPage();
            }
            return RedirectToCurrentUmbracoPage();
        }
    

    Any pointers would be appreciate ;)

Please Sign in or register to post replies

Write your reply to:

Draft