Copied to clipboard

Flag this post as spam?

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


  • Moran 285 posts 934 karma points
    May 12, 2015 @ 18:05
    Moran
    0

    Validation messages not showing after post back

    Hi I am using umbraco 7.2.1 and I am trying to validate my model, but after the post back I don't get any validation for my checkbook or file. The validation works but it's not showing the errors after a post back, the client validations works fine.

    this is my model

     public class FileContactViewModel
    {
        [UmbracoRequired(ErrorMessageDictionaryKey = "Required", PropertyDictionaryKey = "Name")]
        public string Name { get; set; }
        [UmbracoRequired(ErrorMessageDictionaryKey = "Required", PropertyDictionaryKey = "Email")]
        [UmbracoEmail(ErrorMessageDictionaryKey = "InvalidEmail", PropertyDictionaryKey = "Email")]
        public string Email { get; set; }
        [UmbracoRequired(ErrorMessageDictionaryKey = "Required", PropertyDictionaryKey = "File")]
        [FileSize(102400)]
        [FileTypes("doc,docx,jpeg,jpg,pdf")]
        public HttpPostedFileBase File { get; set; }
        [UmbracoMustBeTrue(ErrorMessageDictionaryKey = "Required", PropertyDictionaryKey = "Terms")]
        public bool TermsAndConditions { get; set; }    
    }
    

    this is the controller

    [HttpPost]
        public ActionResult SendDocFile(FileContactViewModel model)
        {
            if (model.File.HasFile() && ModelState.IsValid)
            {
                try
                {
                    var fileName = Path.GetFileName(model.File.FileName);
                    var path = Path.Combine(Server.MapPath("~/media/"), fileName);
                    model.File.SaveAs(path);
                }
                catch (Exception ex)
                {
                    TempData["fileUploadStatus"] = "ERROR:" + ex.Message.ToString();
                }
    
                var message = new MailMessage(ConfigurationManager.AppSettings["EmailFrom"], ConfigurationManager.AppSettings["EmailTo"]);
                var client = new SmtpClient();
    
                message.Subject = "פניה מדף צור קשר";
                message.Body += "שם" + ": " + model.Name + "\n";
                message.Body += "אימייל" + ": " + model.Email + "\n";
    
                Attachment docFile = new Attachment(model.File.InputStream, model.File.FileName);
                message.Attachments.Add(docFile);
    
                client.Send(message);
    
                TempData["success"] = true;
            }
            return RedirectToCurrentUmbracoPage();
        }
    

    and this is the view

        @inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco710Source.Models.FileContactViewModel>
    @using Umbraco710Source.Controllers
    
    @{
    
    }
    @if (TempData["success"] == null)
    {
        using (Html.BeginUmbracoForm("SendDocFile", "ContactSurface", new { @class = "post_form v_form_Hibur form-horizontal m_b_no_space", enctype = "multipart/form-data" }))
        {
            <ul class="post_form v_form_Hibur form-horizontal m_b_no_space">
                <li class="clearfix">
                    <div class="fright half_column" style="padding-left: 15px;">
                        @Html.TextBoxFor(m => m.Name, new { @placeholder = "שם מלא" })
                        @*<input type="text" id="cf_name" name="cf_name" placeholder="שם" class="full_width">*@
                    </div>
                    <div class="fright half_column">
                        @Html.TextBoxFor(m => m.Email, new { @placeholder = "דואר אלקטרוני" })
                        @*<input type="text" id="cf_name" name="cf_name" placeholder="אימייל" class="full_width">*@
                    </div>
    
                    <div class="fright full_column">
                        @Html.CheckBoxFor(m => m.TermsAndConditions, new { @id = "Checkbox1" })
                        @*<input id="Checkbox1" type="checkbox" />*@
                        <label class="labelCheckbox">
                            <a href="/%D7%AA%D7%A7%D7%A0%D7%95%D7%9F-%D7%95%D7%AA%D7%A0%D7%90%D7%99-%D7%A9%D7%99%D7%9E%D7%95%D7%A9/">
                                מסכים לתקנון ולתנאי השימוש
                            </a>
                        </label>
                    </div>
                    <div class="fright full_column">
                        <input class="labelbrowse" type="file" name="file" />
                        <div id="file">צרף קובץ word, pdf או jpg</div>
                        @* <label class="labelbrowse">צרף קובץ וורד</label>*@
                        <button class="btn-small hibur">שלח</button>
                        <p class="cochavit">* ניתן לשלוח חיבור אחד בלבד לכל גולש</p>
                        @Html.ValidationMessageFor(m => m.Name)
                        @Html.ValidationMessageFor(m => m.Email)
                        @Html.ValidationMessageFor(m => m.TermsAndConditions)
                    </div>
                    <div>
                        @(TempData["fileUploadStatus"] = Html.ValidationMessageFor(m => m.File))
                        @TempData["fileUploadStatus"]
                    </div>
                </li>
            </ul>
        }
    }
    

    I think that the issue is with

     RedirectToCurrentUmbracoPage()
    

    method

  • Moran 285 posts 934 karma points
    May 14, 2015 @ 09:23
    Moran
    0

    Someone has an idea how to resolve this issue? Thanks

  • Moran 285 posts 934 karma points
    Sep 06, 2015 @ 05:37
    Moran
    0

    Can someone help with this issue? I can't seem to find the reason for this. Thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies