Copied to clipboard

Flag this post as spam?

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


  • Alan Johnstone 10 posts 101 karma points
    Feb 13, 2018 @ 11:41
    Alan Johnstone
    0

    Saving input to session

    Hi Can't figure this out - hence the post :) I am using V7.8.1 so models builder is also installed and enabled. I have changed the mode to AppData to allow me to extend the models. This is all good I have a HomeTemp partial class

    {
        public string PetName
        {
            get;            set;
        }
    
        public string CallerName
        {
            get; set;
        }
    
    }
    

    Controller

    public class HomeTempSurfaceController : SurfaceController
    {
        public ActionResult ShowForm(HomeTemp homeTemp)
        {
            homeTemp.PetName = "Fido";
            return PartialView(viewName: "HomeTempPartial", model: homeTemp);
        }
        public ActionResult HandleFormPost(string submitButton, HomeTemp homeTemp)
        {
            Session["CallerName"] = homeTemp.CallerName;
            Session["PetName"] = homeTemp.PetName;
    
            return Redirect(homeTemp.Start.Url);
        }
    }
    

    And a partial view

    @inherits UmbracoViewPage<HomeTemp>
    
    @using (Html.BeginUmbracoForm<VFUmbraco.Controllers.HomeTempSurfaceController>("HandleFormPost"))
    {
        <div class="container-fluid">
            <div class="container">
                <label for="CallerName">Caller Name:</label>@Html.EditorFor(x => x.CallerName)
            </div>
        </div>
        <div class="container-fluid">
            <div class="container">
                <label for="PetName">Pet Name:</label>@Html.EditorFor(x => x.PetName)
            </div>
        </div>
        <div class="container-fluid">
            <div class="container">
                <input type="submit" value="Submit" />
            </div>
        </div>
    }
    

    The page loads correctly with the textbox field PetName prepopulated with 'Fido'. Which can be edited and caller name can be added. The submit is posting the model to the controller but the model has null values for PetName and CallerName.

    Can anyone see what I'm doing wrong? Thanks Alan

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Feb 13, 2018 @ 12:21
    Alex Skrypnyk
    0

    Hi Alan

    What if you remove "submitButton" param from the action? Like that:

    public ActionResult HandleFormPost(HomeTemp homeTemp)
    

    Alex

  • Alan Johnstone 10 posts 101 karma points
    Feb 13, 2018 @ 12:45
    Alan Johnstone
    0

    Hi Alex

    Thanks for trying, took it out incase it was causing something wierd but still the same. Cheers Alan

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Feb 13, 2018 @ 13:41
    Steve Morgan
    0

    Hi Alan,

    I wonder if it's because you're using EditorFor which will generate html for all fields in the model but you're specifying them individually.

    Change these to @Html.TextBoxFor and see if that solves it.

    HTH Steve

  • Alan Johnstone 10 posts 101 karma points
    Feb 13, 2018 @ 14:02
    Alan Johnstone
    0

    Hi Steve

    Thanks, I'd started with .TextBoxFor and then found a post explaining EditorFor gives more functionality.

    Cheers Alan

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Feb 13, 2018 @ 14:10
    Steve Morgan
    0

    Did that fix it?

  • Alan Johnstone 10 posts 101 karma points
    Feb 13, 2018 @ 14:13
    Alan Johnstone
    0

    Hi Steve

    Unfortunatly not but thanks.

    Alan

  • Alan Johnstone 10 posts 101 karma points
    Feb 13, 2018 @ 15:51
    Alan Johnstone
    100

    Hi I've got round it by using

    @using (Html.BeginForm("HandleFormPost", "HomeTempSurface"))
    

    and

    public ActionResult HandleFormPost( FormCollection homeTemp)
    

    far from ideal so if any kind person out there sees where I'm going wrong and can post a proper slution it would be appreciated.

    Thanks for reading this far and good luck.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Feb 13, 2018 @ 19:37
    Alex Skrypnyk
    0

    Thanks, Alan, for sharing the solution with our community

  • Alan Johnstone 10 posts 101 karma points
    Feb 14, 2018 @ 08:18
    Alan Johnstone
    0

    Wouldn’t mark it as a solution. There most be a way of using passing the edited data within the model. I’m missing something stupid. Cheers Alex Alan

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Feb 15, 2018 @ 19:25
    Alex Skrypnyk
    0

    Hi Alan

    Sorry for marking the topic as solved.

    This code works for me:

    Veiw:

    using (Html.BeginUmbracoForm<UmbRegisterController>("HandleRegisterMember"))
        {
            <fieldset>
                <legend>Register Member</legend>
    
                @Html.ValidationSummary("registerModel", true)
    
                @Html.LabelFor(m => registerModel.Name)
                @Html.TextBoxFor(m => registerModel.Name)
    }
    

    Controller:

    [HttpPost]
            public ActionResult HandleRegisterMember([Bind(Prefix = "registerModel")]RegisterModel model)
    {}
    

    /Alex

  • Alan Johnstone 10 posts 101 karma points
    Mar 14, 2018 @ 09:12
    Alan Johnstone
    0

    Thanks again Alex. Issue appears to be related to the Models Builder which is now rolled into the Umbraco release, or to be more precise my use of models along with the builders generated models. If anyone else having this problem the solution is best explained at https://stackoverflow.com/questions/41913529/how-to-post-a-custom-model-to-a-controller-in-umbraco-7-5-8 Thanks to Alex and Steve for replying.

Please Sign in or register to post replies

Write your reply to:

Draft