Copied to clipboard

Flag this post as spam?

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


  • blackhawk 313 posts 1367 karma points
    Aug 15, 2017 @ 22:31
    blackhawk
    0

    Missing route from route collection

    I just started playing with Umbraco 7.6.5. today. I tried creating a contact form via MVC but I am getting the following message when I try to load my page in the browser...

    A route named 'SubmitForm' could not be found in the route collection.
    Parameter name: name
    

    My ContactForm view looks like this...

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    
    <div class="container">
        @{ Html.RenderAction("RenderForm", "ContactForm");}
    </div>
    

    My _Contact partial view looks like this:

       @inherits UmbracoViewPage<umb00.Models.ContactForm>
    
        @using (Html.BeginRouteForm("SubmitForm", "ContactForm", FormMethod.Post))
        {
    
            @Html.AntiForgeryToken()
            @Html.ValidationSummary()
    
            @Html.LabelFor(m => m.FirstName)
            @Html.TextBoxFor(m => m.FirstName)
            //@Html.ValidationMessageFor(m => m.FirstName)
    
            @Html.LabelFor(m => m.LastName)
            @Html.TextBoxFor(m => m.LastName)
    
            @Html.LabelFor(m => m.EmailAddress)
            @Html.TextBoxFor(m => m.EmailAddress)
    
            @Html.LabelFor(m => m.Message)
            @Html.TextAreaFor(m => m.Message)
    
            <button>Submit</button>
        }
    

    and my ContactFormController looks like this:

    using Umbraco.Web.Mvc;
    using System.Web.Mvc;
    using umb00.Models;
    using System.Net.Mail;
    
    namespace umb00.Controllers
    {
        public class ContactFormController : 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(ContactForm model)
            {
                if (ModelState.IsValid)
                {
                    //send an email
                    SendEmail(model);
                    return RedirectToCurrentUmbracoPage();
                }
                //if not valid go back to the page
                return CurrentUmbracoPage();
            }
    
            private void SendEmail(ContactForm model)
            {
                MailMessage message = new MailMessage(model.EmailAddress, "[email protected]");
                message.Subject = string.Format("Enquiry 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);
            }
        }
    }
    

    Any advice would be great thanks!

  • David Brendel 786 posts 2949 karma points c-trib
    Aug 16, 2017 @ 06:22
    David Brendel
    0

    Hi,

    when doing form stuff always use BeginUmbracoForm so that umbraco can wire up the routing correctly.

    Would be my first guess on what's wrong.

    Regards David

  • Lewis Smith 199 posts 586 karma points c-trib
    Aug 16, 2017 @ 07:30
    Lewis Smith
    0

    Hi,

    Looks like you're following one of the Paul's YouTube tutorials. Theses are great.

    I have the same issue when following this once, and never resolved the issue, although I didn't try using BeginUmbracoForm like David suggested.

    The way i fixed this was to stop Umbraco from running, and rebuild the solution.

    ~ Lewis

  • 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