Copied to clipboard

Flag this post as spam?

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


  • Allan 42 posts 192 karma points
    Nov 28, 2019 @ 13:25
    Allan
    0

    Unable to resolve type: InstallUmbraco.Controllers.ContactSurfaceController, service name:

    I have a basic feedback form on my page. This is the surface controller...

    using Umbraco.Web.Mvc;
    using System.Web.Mvc;
    using InstallUmbraco.Models;
    using System.Net.Mail;
    
    namespace InstallUmbraco.Controllers
    {
        /// <summary>
        /// Surface controller for contact form model
        /// </summary>
        public class ContactSurfaceController : SurfaceController
        {
            public ActionResult Renderform()
            {
                return PartialView("~/Views/Partials/_Contact.cshtml");
            }
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult SubmitForm(ContactModel model)
            {
                if(ModelState.IsValid)
                {
                    SendEmail(model);
                    return PartialView("~/Views/Partials/_Contact_SUCCESS.cshtml");
                    }
                    return PartialView("~/Views/Partials/_Contact_FAIL.cshtml");
                }
    
                private void SendEmail(ContactModel model)
                {
                    string htmlMsg = "<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">";
                    htmlMsg = htmlMsg + "<tr><td>Name:</td><td><strong>" + model.YourName + "</strong></td></tr>";
                    htmlMsg = htmlMsg + "<tr><td>Email:</td><td><strong>" + model.YourEmail + "</strong></td></tr>";
                    htmlMsg = htmlMsg + "<tr><td>Message:</td><td><strong>" + model.YourMessage + "</strong></td></tr>";
                    htmlMsg = htmlMsg + "</table>";
    
                    string subject = string.Format("Enquiry from {0} - {1}", model.YourName, model.YourEmail);
    
                    MailMessage message = new MailMessage("[email protected]", "[email protected]", subject, htmlMsg);
                    message.IsBodyHtml = true;
                    SmtpClient client = new SmtpClient();
                    client.Send(message);
                }
            }
        }
    

    The Partial view looks like this...

    @inherits UmbracoViewPage<InstallUmbraco.Models.ContactModel>
    <div id="formOuter">
        @using (Ajax.BeginForm("SubmitForm", "ContactSurface", null, new AjaxOptions
        {
            HttpMethod = "POST",
            InsertionMode = InsertionMode.Replace,
            UpdateTargetId = "formOuter"
        }))
        {
            @Html.AntiForgeryToken()
            <div class="grid-x" id="js-contact-form">
                <div class="cell small-12 redText" id="js-contact-form-errors">
                    @Html.ValidationSummary()
                </div>
                <div class="cell small-12">
                    <label>
                        Name:
                        @Html.TextBoxFor(m => m.YourName, new { placeholder = "Your Name" })
                    </label>
                </div>
                <div class="cell small-12">
                    <label>
                        Email:
                        @Html.TextBoxFor(m => m.YourEmail, new { placeholder = "[email protected]", type = "email" })
                    </label>
                </div>
                <div class="cell small-12">
                    <label>
                        Message:
                        @Html.TextAreaFor(m => m.YourMessage, new { placeholder = "Your message...", rows = "5" })
                    </label>
                </div>
                <div class="cell small-12">
                    <button class="button use-ajax">Submit</button>
                </div>
            </div>
        }
    </div>
    

    It seemed to work well, but after reboots, etc. I get the YSOD with the following info...

    Unable to resolve type: InstallUmbraco.Controllers.ContactSurfaceController, service name:

    Can anyone help or explain why this is happening periodically?

    Thanks in advance!

Please Sign in or register to post replies

Write your reply to:

Draft