Copied to clipboard

Flag this post as spam?

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


  • Remi Martel 32 posts 104 karma points
    Mar 21, 2018 @ 19:28
    Remi Martel
    0

    I extended the Umbraco model.generated with a custom model and I have an Umbraco form in a partial view returning to my controller with a post. I read a bunch of posts, but I can't figure out why my form returns an empty model to my controller. I set a breakpoint at the beginning of my function in my controller and no matter what I entered in the form, all the fields are null.

    Here is my controller :

    [HttpGet]
        public ActionResult Register(Register model)
        {
            return PartialView("_Register", model);
        }
    
        [HttpPost]
        [ActionName("Register")]
        public ActionResult RegisterPost(Register model)
        {
            return PartialView("_Register", model);
        }
    
        [HttpPost]
        public ActionResult SendRegistration(Register model)
        {
    

    Bunch of validation and code of model isValid What matters is that model.FirstName, model.LastName ... are all null

            return CurrentUmbracoPage();
        }
    

    Here is my model:

    namespace Umbraco.Web.PublishedContentModels{
    public partial class Register
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string PhoneNumber { get; set; }
        public string EmailAddress { get; set; }
        public string ConfirmEmailAddress { get; set; }
        public string Password { get; set; }
        public string ConfirmPassword { get; set; }
        public bool NewsLetterOptIn { get; set; }
        public bool AcceptConditions { get; set; }
        public string GroupKey { get; set; }
    }
    

    And finally here is my form partial view:

    @using System.Web.Mvc.Html
    @using Lancite.EPhoto3.API.Extensions
    @using Umbraco.Web
    @using EphotoUmbraco.Controllers
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Register>
    @using ContentModels = Umbraco.Web.PublishedContentModels
    

    ...

    @*, "Account", FormMethod.Post, new { @role = "form", @name = "frmRegister", @id = "frmRegister" }))*@
                @using (Html.BeginUmbracoForm<AccountController>("SendRegistration"))
                {
                    <div class="form-box">
                        <div class="row">
                            <div class="col-xs-12">
                                <div class="header">
                                    <h2>@Umbraco.GetDictionaryValue("CreateAccount")</h2>
                                    <p>@Umbraco.GetDictionaryValue("AlreadyHaveAccount") <a href="@Url.Action("Login", "Account")">@Umbraco.GetDictionaryValue("Here")</a> @Umbraco.GetDictionaryValue("ToLogin")</p>
                                </div>
    
                                @Html.LabelFor(m => m.FirstName, Umbraco.GetDictionaryValue("FirstName"), new { @class = "control-label" })
                                <div class="margin-bottom-20 @Html.ValidationErrorFor(m => m.FirstName, "has-error")">
                                    @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control", @type = "text", @tabindex = "1" })
                                </div>
    
                                @Html.LabelFor(m => m.LastName, Umbraco.GetDictionaryValue("LastName"), new { @class = "control-label" })
                                <div class="margin-bottom-20 @Html.ValidationErrorFor(m => m.LastName, "has-error")">
                                    @Html.TextBoxFor(m => m.LastName, new { @class = "form-control", @type = "text", @tabindex = "2" })
                                </div>
    
                                @Html.HiddenFor(m => m.GroupKey)
    
                                @Html.LabelFor(m => m.PhoneNumber, Umbraco.GetDictionaryValue("PhoneNumber"), new { @class = "control-label" })
                                <div class="margin-bottom-20 @Html.ValidationErrorFor(m => m.PhoneNumber, "has-error")">
                                    @Html.TextBoxFor(m => m.PhoneNumber, new { @class = "form-control", @type = "tel", @tabindex = "3" })
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-6">
                                @Html.LabelFor(m => m.EmailAddress, Umbraco.GetDictionaryValue("Email"), new { @class = "control-label" })
                                <div class="margin-bottom-20 @Html.ValidationErrorFor(m => m.EmailAddress, "has-error")">
                                    @Html.TextBoxFor(m => m.EmailAddress, new { @class = "form-control", @type = "email", @tabindex = "4" })
                                </div>
                            </div>
                            <div class="col-sm-6">
                                @Html.LabelFor(m => m.ConfirmEmailAddress, Umbraco.GetDictionaryValue("ConfirmEmail"), new { @class = "control-label" })
                                <div class="margin-bottom-20 @Html.ValidationErrorFor(m => m.ConfirmEmailAddress, "has-error")">
                                    @Html.TextBoxFor(m => m.ConfirmEmailAddress, new { @class = "form-control", @type = "email", @tabindex = "5" })
                                </div>
                            </div>
                        </div>
    

    ... bunch of other fields ...

                        <div class="row">
                            <div class="col-lg-8">
                                <label class="checkbox remember">
                                    @Html.CheckBoxFor(m => m.AcceptConditions)
                                    @Html.LabelFor(m => m.AcceptConditions)<span> <b><a href="@Url.Action("TermsOfUse", "Home")" target="_blank">@Umbraco.GetDictionaryValue("TermsOfUse")</a></b></span>
                                </label>
                                <label class="checkbox remember">
                                    @Html.CheckBoxFor(m => m.NewsLetterOptIn)
                                    <label for="NewsLetterOptIn">@Umbraco.GetDictionaryValue("ReceiveInfoLetter")</label>
                                </label>
                                <ul>
                                    @Umbraco.GetDictionaryValue("InfoLetterDetails")
                                </ul>
                                <div class="font-bold">@Umbraco.GetDictionaryValue("WithdrawConsent")</div>
                            </div>
                            <div class="col-md-4" id="btnSubmitContainer">
                                <button class="btn btn-u btn-u-default btn-create-account" type="submit" id="btnSubmitRegister">@Umbraco.GetDictionaryValue("Continue")</button>
                            </div>
                        </div>
                    </div>
                }
    

    Sorry for the bunch of code, most of it is repetition or really quick to understand.

    Basically, why are the parameters model in SendRegistration(Register model) in my controller empty

  • Mila Pandurska 43 posts 190 karma points
    Mar 23, 2018 @ 21:09
    Mila Pandurska
    0

    Hi Remi, Is there a reason that you extend umbraco Register model. My advice is to create your own custom model - RegisterModel with the same properties. If you still experiance the issue we can investigate further.

    Mila

  • Remi Martel 32 posts 104 karma points
    Mar 26, 2018 @ 12:04
    Remi Martel
    0

    Resolved: Thanks, Mila. I was extending the Umbraco models because otherwise, there is information such as language and other references that were passed without any code from my part using return CurrentUmbracoPage. Since then, I have read another post that said not to extend Umbraco models because it is not something fully functional yet. So I will use my own model and pass the missing element manually.

Please Sign in or register to post replies

Write your reply to:

Draft