Copied to clipboard

Flag this post as spam?

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


  • glenatron 37 posts 132 karma points
    Jan 07, 2014 @ 17:16
    glenatron
    0

    Form created with BeginUmbracoForm posts back an empty model in 6.1.6

    I have a form that looks like this:

    using (Html.BeginUmbracoForm("SubmitStory", "NewsStorySubmitSurface"))
    {
       <p>
         @Html.LabelFor(x => storyModel.Headline)  @Html.TextBoxFor(x => storyModel.Headline)
       </p>
       <p>
         @Html.LabelFor(x => storyModel.Standfirst)  @Html.TextAreaFor(x => storyModel.Standfirst)
       </p>
       <p>
         @Html.LabelFor(x => storyModel.Story) @Html.TextAreaFor(x => storyModel.Story)
       </p>
       <input type="submit" />
    }
    

    Now in my NewsStorySubmitSurface controller I have the following:

        public ActionResult SubmitStory(NewsStorySubmitModel model)
        {
            var newsStory = Services.ContentService.CreateContent(model.Headline, GetParentId(), "newsStoryType");
            // do stuff
         }
    

    What I am noticing is that my the model parameter in the code is always coming in with empty properties. However, in the Request.Form list, all the properties exist.

    Obviously, I can set them by hand, but why is Umbraco not doing this automatically? If I do @Html.EditorFor(storyModel) it also appears to pass down this empty model. I guess I'll have to get the posted values manually, but it seems like I shouldn't have to.

  • Marcio Goularte 374 posts 1346 karma points
    Jan 07, 2014 @ 20:52
    Marcio Goularte
    0

    Hi glanaton,

    your form is in Macro Script or Partial View?

  • Charles Afford 1163 posts 1709 karma points
    Jan 07, 2014 @ 22:47
    Charles Afford
    0

    Can you paste all of your code please.  Its most likely that you have a wrong name or something invalid when passing in the model.  Charlie.  Are you model properties being set correctly in your form?

    Charlie :)

  • glenatron 37 posts 132 karma points
    Jan 08, 2014 @ 00:23
    glenatron
    0

    Thanks for the replies- what was happening was that the Model I was using to create the form was not the Model object that the page was built from- I was using StoryModel storyModel = new StoryModel() to create it, which apparently Umbraco doesn't like.

    By breaking out the form functionality into a strongly typed partial, it seems to work alright- it looks as though unless the model is called "Model" it won't be passed to the SurfaceController correctly. No idea if that is an Umbraco or MVC constraint, though.

Please Sign in or register to post replies

Write your reply to:

Draft