Copied to clipboard

Flag this post as spam?

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


  • Daniel 22 posts 214 karma points
    Sep 19, 2017 @ 00:12
    Daniel
    0

    Cannot find the Umbraco route definition in the route values

    Hey guys,

    I just finished a site with Umazel Starter Kit but I cannot get the contact form to work. I've been getting "Internal server error 500" which led me to debug and realized I was getting the following error in the code:

    enter image description here

    This is the entire controller code:

     public ActionResult Index()
            {
                return PartialView("ContactView", new ContactViewModel());
            }
    
            [HttpPost]
            [NotChildAction]
            public ActionResult Submit(ContactViewModel form)
            {
    
                if (!ModelState.IsValid)
                {
                    return Json(new { Success = false });
                }
    
                SectionContact currSection = (SectionContact)Umbraco.TypedContent(form.CurrentSectionId);
    
                string mailTo = currSection.AdministratorsEmail;
                string mailFrom = currSection.NotificationMailFrom;
                string mailFromAlias = currSection.NotificationMailSenderAlias;
                string message = string.Concat(currSection.NotificationEmailBody, "<br/><br/>", umbraco.library.StripHtml(form.Message));
    
                //Use predefined subject. If predefined subject is not defined, use current subject from form (if any)
                string subject = (string.IsNullOrEmpty(currSection.NotificationEmailSubject)) ? form.Subject : currSection.NotificationEmailSubject;
    
                //If all else fails, use standard subject from dictionary.
                subject = (string.IsNullOrEmpty(subject)) ? Umbraco.GetDictionaryValue("ContactForm.Subject") : subject;
    
                StringBuilder sb = new StringBuilder(string.Empty);
    
                if (!string.IsNullOrEmpty(form.Name))
                {
                    sb.Append("Name:");
                    sb.Append("<br/>");
                    sb.Append(form.Name);
                    sb.Append("<br/><br/>");
                }
    
                if (!string.IsNullOrEmpty(form.Subject))
                {
                    sb.Append("Subject:");
                    sb.Append("<br/>");
                    sb.Append(form.Subject);
                    sb.Append("<br/><br/>");
                }
    
                sb.Append("Email: ");
                sb.Append("<br/>");
                sb.Append(form.Email);
                sb.Append("<br/><br/>");
    
                sb.Append("Message: ");
                sb.Append("<br/>");
                sb.Append(umbraco.library.ReplaceLineBreaks(message));
                sb.Append("<br/><br/>");
    
                if (!string.IsNullOrEmpty(currSection.Dropdown1Values))
                {
                    sb.Append(currSection.Dropdown1Values.Split(new string[] { "\n", "\n\r" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                    sb.Append("<br/>");
                    sb.Append(form.DropDown1);
                    sb.Append("<br/><br/>");
                }
    
                if (!string.IsNullOrEmpty(currSection.Dropdown2Values))
                {
                    sb.Append(currSection.Dropdown2Values.Split(new string[] { "\n", "\n\r" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                    sb.Append("<br/>");
                    sb.Append(form.DropDown2);
                    sb.Append("<br/><br/>");
                }
    
                if (ModelState.IsValid)
                {
                    Utils.SendEmail(mailFrom, mailFromAlias, mailTo, subject, sb.ToString());
                }
    
                return Json(new { Success = true });
            }
    
    
        }
    

    And this is the view:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContactViewModel>
    @using DotSee.UmbracoExtensions
    @using DotSee.Models
    @using DotSee.Controllers
    @using Umbraco.Web
    @using ClientDependency.Core.Mvc;
    
    @{
        Html.RequiresJs("/scripts/jquery.unobtrusive-ajax.min.js",9999);
        Html.RequiresJs("/scripts/jquery.validate.min.js", 9999);
        Html.RequiresJs("/scripts/jquery.validate.unobtrusive.min.js", 9999);
    
        int currSectionId = Convert.ToInt32(ViewData["currSectionId"]);
        bool hideSubject = (bool)ViewData["hideSubject"];
        bool hideName = (bool)ViewData["hideName"];
        string[] dropDown1Data = (ViewData["dropDown1Data"] as string[]);
        string[] dropDown2Data = (ViewData["dropDown2Data"] as string[]);
    }
    
    
            <div class="row">
                <div id="contactFormMessages" class="ptb-0 col-md-6 col-md-offset-3 text-center">
    
                    <h6 id="contactSuccess" class="successContent">
                        <i class="fa fa-check left" style="color: #5cb45d;"></i>@Umbraco.GetDictionaryValue("ContactForm.Success")
                    </h6>
    
                    <h6 class="errorContent">
                        <i class="fa fa-exclamation-circle left" style="color: #e1534f;"></i>@Umbraco.GetDictionaryValue("ContactForm.Failure")
                    </h6>
    
                   </div>
    
                <div id="contactFormHolder" class="col-md-6 col-md-offset-3">
                    @using (Ajax.BeginForm("Submit", "ContactSurface", new AjaxOptions
                    {
                        HttpMethod = "POST",
                        OnFailure = "ShowContactError",
                        OnSuccess = "ShowContactSuccess",
                    }))
                    {
    
                        @Html.TextBoxFor(model => model.CurrentSectionId, new { Value = Convert.ToInt32(currSectionId) })
                        if (!hideName)
                        {
                            <div class="form-field-wrapper">
                                @Html.TextBoxFor(model => model.Name, new { @Placeholder = "Nombre Completo", @class = "input-sm form-full" })
                            </div>
                        }
                        <div class="form-field-wrapper">
                            @Html.TextBoxFor(model => model.Email, new { @Placeholder = "Correo Electrónico", @class = "input-sm form-full" })
                            @Html.ValidationMessageFor(model => model.Email, Umbraco.GetDictionaryValue("ContactForm.Email.Invalid"))
                        </div>
                        if (!hideSubject)
                        {
                            <div class="form-field-wrapper">
                                @Html.TextBoxFor(model => model.Subject, new { @Placeholder = "Sujeto", @class = "input-sm form-full" })
                            </div>
                        }
                        <div class="form-field-wrapper">
                            @Html.TextAreaFor(model => model.Message, new { @Placeholder = "Mensaje", @class = "form-full", @rows = 7 })
                            @Html.ValidationMessageFor(model => model.Message, Umbraco.GetDictionaryValue("ContactForm.Message.Required"))
                        </div>
                        if (dropDown1Data != null && dropDown1Data.Length > 1)
                        {
                            @Html.DropDownListFor(model => model.DropDown1, dropDown1Data.Select(f => new SelectListItem { Value = f, Text = f }).Skip(1), dropDown1Data[0], new { @class = "form-full" })
                        }
                        if (dropDown2Data != null && dropDown2Data.Length > 1)
                        {
                            @Html.DropDownListFor(model => model.DropDown2, dropDown2Data.Select(f => new SelectListItem { Value = f, Text = f }).Skip(1), dropDown2Data[0], new { @class = "form-full" })
                        }
                        <button class="btn btn-md btn-black form-full" type="submit" id="form-submit" name="submit">@Umbraco.GetDictionaryValue("ContactForm.Submit")</button>
                    }
                </div>
            </div>
    
    <script type="text/javascript">
    
        function ShowContactError() {
             $(".errorContent").show();
                $("#contactFormHolder").hide();
        }
    
        function ShowContactSuccess(arg) {
            if (arg.Success === true) {
                $("#contactSuccess").show();
                $("#contactFormHolder").hide();
            }
            else
            {
                $(".successContent").show();
                $("#contactFormHolder").hide();
    
            }
        }
    
    </script>
    
Please Sign in or register to post replies

Write your reply to:

Draft