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 9 posts 100 karma points
    6 days ago
    Alan Johnstone
    0

    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 4265 posts 15409 karma points
    6 days ago
    Alex Skrypnyk
    0

    Hi Alan

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

    public ActionResult HandleFormPost(HomeTemp homeTemp)
    

    Alex

  • Alan Johnstone 9 posts 100 karma points
    6 days ago
    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 887 posts 2626 karma points c-trib
    6 days ago
    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 9 posts 100 karma points
    6 days ago
    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 887 posts 2626 karma points c-trib
    6 days ago
    Steve Morgan
    0

    Did that fix it?

  • Alan Johnstone 9 posts 100 karma points
    6 days ago
    Alan Johnstone
    0

    Hi Steve

    Unfortunatly not but thanks.

    Alan

  • Alan Johnstone 9 posts 100 karma points
    6 days ago
    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 4265 posts 15409 karma points
    6 days ago
    Alex Skrypnyk
    0

    Thanks, Alan, for sharing the solution with our community

  • Alan Johnstone 9 posts 100 karma points
    5 days ago
    Alan Johnstone
    0

    Wouldnt mark it as a solution. There most be a way of using passing the edited data within the model. Im missing something stupid. Cheers Alex Alan

  • Alex Skrypnyk 4265 posts 15409 karma points
    4 days ago
    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 9 posts 100 karma points
    3 days ago
    Alan Johnstone
    0

    Hi Alex

    Thanks for this, I'm on a different project today and away on holiday tomorrow for a week. Will try it out when I get back.

    Take care Alan

Please Sign in or register to post replies

Write your reply to:

Draft