Copied to clipboard

Flag this post as spam?

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


  • Lewis Smith 211 posts 620 karma points c-trib
    Jul 12, 2017 @ 10:10
    Lewis Smith
    0

    Could not find a Surface controller route in the RouteTable for controller name

    Hi all,

    I'm creating a form and I'm coming a cross a routing issue, I have created forms in this exact way before but have never come across this issue.

    I have included a screenshot of the error I'm getting as well as the code i have.

    I have googled the issue and a lot of forums are saying i need to add the routing to a routing file found in the app_start folder but I cant find this anywhere, is this correct?

    enter image description here

    //MODEL

    using System.ComponentModel;
    
    namespace est1897_umbraco.Models
    {
        public class HomepageFormViewModel
        {
            [DisplayName("Pagename")]
            public string PageName { get; set; }
    
        [DisplayName("Title:")]
        public string Title { get; set; }
    
        [DisplayName("Firstname:")]
        public string Firstname { get; set; }
    
        [DisplayName("Surname:")]
        public string Surname { get; set; }
    
        [DisplayName("Telephone:")]
        public string Telephone { get; set; }
    
        [DisplayName("Email:")]
        public string Email { get; set; }
    
        [DisplayName("Against my assets:")]
        public string Asset { get; set; }
    
        [DisplayName("I would like to borrow:")]
        public string BorrowAmount { get; set; }
    }
    }
    

    //CONTROLLER

    using System.Web.Mvc;
    using est1897_umbraco.Models;
    using Umbraco.Web.Mvc;
    using System.Net.Mail;
    
    namespace est1897_umbraco.Controllers
    {
        public class HomepageFormController : SurfaceController
        {
            public ActionResult RenderForm()
            {
                return PartialView("~/Views/Partials/Forms/HomepageForm.cshtml");
            }
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult SubmitForm(HomepageFormViewModel model)
            {
                if (ModelState.IsValid)
                {
                    SendEmail(model);
                    TempData["Success"] = true;
                    return RedirectToCurrentUmbracoPage();
                }
                return CurrentUmbracoPage();
            }
            private void SendEmail(HomepageFormViewModel model)
            {
                MailMessage message = new MailMessage(model.Email, "[email protected]");
                message.Subject = string.Format("Enquiry from {0} {1} {2} - {3}", model.Title, model.Firstname, model.Surname, model.Telephone);
                message.Body = "Title: " + model.Title + "<br>" + 
                               "Name: " + model.Firstname + model.Surname + "<br>" + 
                               "Phone: " + model.Telephone + "<br>" + 
                               "Email: " + model.Email + "<br>" +
                               "Asset: " + model.Asset + "<br>" +
                               "Borrow Amount: " + model.BorrowAmount + "<br>";
                SmtpClient client = new SmtpClient("127.0.0.1", 25);
                client.Send(message);
            }
        }
    }
    

    //FORM VIEW

    @inherits UmbracoViewPage<est1897_umbraco.Models.HomepageFormViewModel>
    @using(Html.BeginUmbracoForm("SubmitForm", "HomepageFormController", new { @class = "js-validate" }))
    {
        @Html.AntiForgeryToken()
    
    <label>Title</label>
    @Html.TextBoxFor(x => x.Title)
    <br />
    <label>Firstname</label>
    @Html.TextBoxFor(x => x.Firstname)
    <br />
    <label>Surname</label>
    @Html.TextBoxFor(x => x.Surname)
    <br />
    <label>Telephone</label>
    @Html.TextBoxFor(x => x.Telephone)
    <br />
    <label>Email</label>
    @Html.TextBoxFor(x => x.Email)
    <br />
    <label>Asset</label>
    @Html.TextBoxFor(x => x.Asset)
    <br />
    <label>Borrow Amount</label>
    @Html.TextBoxFor(x => x.BorrowAmount)
    <br />
    <button>Submit</button>
    }
    

    //VIEW

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
    
    }
    <section class="homepage-form">
        <div class="wrap wrap-large">
         @if (TempData["Success"] != null && (bool)TempData["Success"])
            {
                <p>Form submission success, we will be in touch.</p>
            }
            else
            {
                Html.RenderAction("RenderForm", "HomepageForm");
            }
        </div>
    </section>
    

    Thanks, Lewis

  • Lewis Smith 211 posts 620 karma points c-trib
    Jul 12, 2017 @ 10:36
    Lewis Smith
    0

    I have tried having the form view like this as well, which gets the same error:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<est1897_umbraco.Models.HomepageFormViewModel>
    @using Umbraco.Web
    @using(Html.BeginUmbracoForm<est1897_umbraco.Controllers.HomepageFormController>("SubmitForm", FormMethod.Post))
    {
        @Html.AntiForgeryToken()
        <label>Title</label>
        @Html.TextBoxFor(x => x.Title)
        <br />
        <label>Firstname</label>
        @Html.TextBoxFor(x => x.Firstname)
        <br />
        <label>Surname</label>
        @Html.TextBoxFor(x => x.Surname)
        <br />
        <label>Telephone</label>
        @Html.TextBoxFor(x => x.Telephone)
        <br />
        <label>Email</label>
        @Html.TextBoxFor(x => x.Email)
        <br />
        <label>Asset</label>
        @Html.TextBoxFor(x => x.Asset)
        <br />
        <label>Borrow Amount</label>
        @Html.TextBoxFor(x => x.BorrowAmount)
        <br />
        <button>Submit</button>
    }
    
  • paulthorpe 10 posts 193 karma points
    Jul 12, 2017 @ 16:08
    paulthorpe
    100

    A couple of things to try, in your Original form View, remove Controller from HomepageFormController to the following

    @using(Html.BeginUmbracoForm("SubmitForm", "HomepageForm", new { @class = "js-validate" }))

    In your RenderForm Controller Method you will need to pass through an instance of the Model

    return PartialView("~/Views/Partials/Forms/HomepageForm.cshtml",new est1897_umbraco.Models.HomepageFormViewModel());

  • 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