Copied to clipboard

Flag this post as spam?

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


  • Brett Fullam 119 posts 629 karma points
    Jun 22, 2017 @ 15:13
    Brett Fullam
    0

    Umbraco back office BREAKS after adding a simple controller, model and view for a basic contact form ... ???

    Ok ... I managed to identify exactly WHAT is causing the back office to "break", and now I need help as to figuring out "WHY" this is happening.

    My site does not contain-use any controllers-models prior to this ... and I only added them for the purpose of implementing basic contact form functionality (which was working until I discovered the error in the back office).

    I can replicate the issue from an error-free state of the site. As soon as I add a controller, model and view ... the back office immediately breaks ( throws the DependencyHandler error in the console ) and includes this:

    [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
    

    Am I missing something here ... is there anything that needs to be added prior to creating a controller-model-view for a contact form? The form was actually working before I discovered the error in the back office. This is over my head here ... any suggestions. I can share code for the controller-model-view if that helps.

    Thanks in advance for your help.

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jun 22, 2017 @ 17:50
    Nik
    0

    Hey Brett, me again :-)

    It would be useful to see the controller at the very least :-) If you could share that it might help :-)

  • Brett Fullam 119 posts 629 karma points
    Jun 22, 2017 @ 17:53
    Brett Fullam
    0

    Hey Nik,

    Absolutely ... here's the controller for the form:

    using Umbraco.Web.Mvc;
    using System.Web.Mvc;
    using dynamicNAV.Models;
    using System.Net.Mail;
    
    namespace dynamicNAV.Controllers
    {
        public class ContactSurfaceController : SurfaceController
        {
    
            public const string PARTIAL_VIEW_FOLDER = "~/Views/Partials/Contact/";
    
            public ActionResult RenderForm()
            {
                return PartialView(PARTIAL_VIEW_FOLDER + "_Contact.cshtml");
            }
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult SubmitForm(ContactModel model)
            {
                if(ModelState.IsValid)
                {
                    SendEmail(model);
                    TempData["ContactSuccess"] = true;
                    return RedirectToCurrentUmbracoPage();
    
                }
                return CurrentUmbracoPage();
            }
    
            private void SendEmail(ContactModel model)
            {
                MailMessage message = new MailMessage(model.EmailAddress, "[email protected]");
                message.Subject = string.Format("Inquiry from {0} {1} - {2}", model.FirstName, model.LastName, model.EmailAddress);
                message.Body = model.Message;
                SmtpClient client = new SmtpClient("127.0.0.1", 25);
                client.Send(message);
            }
        }
    }
    

    And here's the model:

    using System.ComponentModel.DataAnnotations;
    
    namespace dynamicNAV.Models
    {
        public class ContactModel
        {
            [Required(ErrorMessage ="The first name field is required")]
            [Display(Name = "First Name:")]
            public string FirstName { get; set; }
    
            [Required(ErrorMessage = "The last name field is required")]
            [Display(Name = "Last Name:")]
            public string LastName { get; set; }
    
            [Required(ErrorMessage = "The email address field is required")]
            [EmailAddress]
            [Display(Name = "Email Address:")]
            public string EmailAddress { get; set; }
    
            [Required(ErrorMessage = "The message field is required")]
            [Display(Name = "Message:")]
            public string Message { get; set; }
        }
    }
    

    And here's the (partial) view:

    @inherits UmbracoViewPage<dynamicNAV.Models.ContactModel>
    
    @using (Html.BeginUmbracoForm("SubmitForm", "ContactSurface", FormMethod.Post))
    {
        @Html.AntiForgeryToken()
    
        <div class="form-group">
            @Html.ValidationSummary()
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.FirstName)
            </div>
            <div class="col-xs-9">
                @Html.TextBoxFor(m => m.FirstName)
            </div>
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.LastName)
            </div>
            <div class="col-xs-9">
                @Html.TextBoxFor(m => m.LastName)
            </div>
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.EmailAddress)
            </div>
            <div class="col-xs-9">
                @Html.TextBoxFor(m => m.EmailAddress)
            </div>
        </div>
    
        <div class="form-group">
            <div class="col-xs-3">
                @Html.LabelFor(m => m.Message)
            </div>
            <div class="col-xs-9">
                @Html.TextAreaFor(m => m.Message)
            </div>
        </div>
            <button>Submit</button>
     }
    

    This is just a basic form to get a handle on the functionality-implementation ... I have 4 forms that will need to be created for this site so this issue is something I have to overcome.

    Thanks again for your help. I really appreciate it.

  • Brett Fullam 119 posts 629 karma points
    Jun 22, 2017 @ 20:54
    Brett Fullam
    0

    OK ... update ... I tried running this controller-model-view example in a clean install of v7.6.3 ... and ... it WORKS (of course) without breaking the back office.

    SO ... it's must be some kind of conflict with an installed package ... but with what? How can I even approach finding it outside of rebuilding my entire site from scratch ...???

    Any suggestions?

  • Brett Fullam 119 posts 629 karma points
    Jun 26, 2017 @ 12:58
    Brett Fullam
    0

    UPDATE ... rolled my site back to an error free state. It's good-to-go again but I need to add forms to the site. There's no getting around this issue for me.

    I'm trying to decide on how to troubleshoot this conflict issue between adding a form using a controller- model-view and whatever is already installed on the site.

    Any recommendations on how to debug this in Visual Studio Community 2015 ... ? I'd hate to think I have to just start uninstalling packages to get to the bottom of this.

  • Brett Fullam 119 posts 629 karma points
    Jun 27, 2017 @ 12:45
    Brett Fullam
    100

    I'm going to close this thread ... I've found more specific information related to what is causing this error and have listed-opened it under this new thread JQuery functions NOT available in Angular (both are located in the Umbraco library?

Please Sign in or register to post replies

Write your reply to:

Draft