Copied to clipboard

Flag this post as spam?

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


  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Dec 10, 2014 @ 15:25
    Ravi Motha
    0

    Form losing values between post and Surfacecontroller

    I have a loevly view  and a with the following form

     

    @using(Html.BeginUmbracoForm("CreateRegistration", "RegisterSurface")) {

       @Html.ValidationSummary(true)

     

            </div>

        <div class="editor-label">

            @Html.LabelFor(m => rvmodel.AccountNumber)

            @Html.TextBoxFor(m => rvmodel.AccountNumber)

            @Html.ValidationMessageFor(m => rvmodel.AccountNumber)

    </div>

     <input type="submit" />

    }

    I output a number of fields

    but when I post to my surface controller I lose my data

    The controller is being accessed fine and tries to process everything 

    public class RegisterSurfaceController: SurfaceController

        {

            [HttpPost]

            [ActionName("CreateRegistration")]

           public ActionResult RegisterPost(RegistrationViewModel tModel)

            {

    tModel is however empty

    Does Stuff in here

    }

    }

     

    but since tmodel is empty I have nothing to process

     

    anyideas

  • Sam 47 posts 153 karma points
    Dec 10, 2014 @ 15:30
    Sam
    0

    Ravi, see my recent post about why I think this is happening and my current workaround:

    http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/59655-Umbraco-7-SurfaceController-Persist-ModelStateModel

  • Sam 47 posts 153 karma points
    Dec 10, 2014 @ 15:40
    Sam
    1

    Deleted. See post from my first response. Use return CurrentUmbracoPage() instead of return RedirectToCurrentUmbracoPage().

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Dec 10, 2014 @ 16:03
    Ravi Motha
    0

    I've trieda version of that.. basically my surface controller looks like this

       public ActionResult RegisterPost(RegistrationViewModel tModel)
        {
    if (ModelState.IsValid)
                {
                    // Send email
                    TempData["success"] = true;
    
    
                    var memberService = Services.MemberService;
    
    
                    //Get values from DB
                    if (CheckAccountExists(tModel))
                    {
    
                        //add user to members
                        string fullName = GetFullName(tModel.AccountNumber);
    
                        if (!CheckMemberExists(tModel))
                        {
    
                            var member = memberService.CreateMember(tModel.EmailAddress, tModel.EmailAddress, fullName,
                                                                    "RegisteredUser");
                            member.SetValue("memberGuid", member.Key);
                            member.IsApproved = true;
    
                            // Don't forget to save all these things
                            memberService.Save(member);
    
                            //do other database actions
                            AddMembertoDatabase(tModel, member.Key);
    
                        }
                        else
                        {
                            ModelState.AddModelError("", "member already exists. Aborting!");
                            return CurrentUmbracoPage();
                        }
    
    
                    }
                    else
                    {
                        ModelState.AddModelError("",
                                                 tModel.EmailAddress +
                                                 ":Account Number Does Not match our records. Aborting!");
                        return CurrentUmbracoPage();
                    }
    
                    return RedirectToCurrentUmbracoPage();
                    // return Redirect("ExtendedRegistration");
                }
                else
                {
                    ModelState.AddModelError("",
                                             "There was an issue posting the variables!");
                }
            }
    

    However I just get the empty TModel..

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Dec 10, 2014 @ 16:49
    Ravi Motha
    0

    Aha its about the way I was setting my @inherits @inherits sets the view base class you need to set the model type

    so i changed my code to make sure the model was and is coming through properly in the p artial and posting to the controller.. I'll update this a bit later

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Dec 15, 2014 @ 12:01
    Ravi Motha
    0

    I found that my issue was related to what i had in the inherits in my template page and in the subsequent partial page

    In my template page I was originally passing a different model @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    and this was interfering with the model i called in the partial

    I now have

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage //template
    @inherits UmbracoViewPage<CorrectViewModel> // partial
    
    @Html.Action("Myxxx", "xxxSurface") //insde my Template
    

    and in my surface controller I added a child action and that seemed to sort me out

     [ChildActionOnly]
            public ActionResult Myxxx()
            {
                return PartialView("Mypartialpage");
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft