Copied to clipboard

Flag this post as spam?

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


  • pat 124 posts 346 karma points
    Feb 02, 2017 @ 09:25
    pat
    0

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

    Hi all,

    I have created a form using MVC and insert in to a RTE (not inside a Grid)

    Form load fine and on submit I get this error "Could not find a Surface controller route in the RouteTable for controller name"

    How to sort this issue please

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 02, 2017 @ 09:37
    Alex Skrypnyk
    0

    Hi Pat

    Can you share the code of form and surface controller?

  • pat 124 posts 346 karma points
    Feb 02, 2017 @ 10:21
    pat
    0
    namespace myumbracoMVC.Controllers
    {
        public class ContactUsController:SurfaceController
        {
    
            [ChildActionOnly]
            public ActionResult Index()
            {
                return PartialView("ContactUs", new ContactUsModel());
            }
    
    
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            [ActionName("Submit")]
            public ActionResult Submit(ContactUsModel model)
            {
                if (!ModelState.IsValid)
                {
                    return CurrentUmbracoPage();
                }
                MailMessage emailmsg = new MailMessage("my@mydomain", "info@mydomain");
                emailmsg.Subject = "message from webSite contact form ";
                emailmsg.Body = "Name : " + model.Name + Environment.NewLine + " Email : " + model.Email + Environment.NewLine + " Telephone : " + model.Telephone + Environment.NewLine + model.Message;
                try
                {
                    SmtpClient smtp = new SmtpClient();
                    smtp.Send(emailmsg);
                }
                catch (Exception ex)
                {
    
                }
                TempData["IsSuccessful"] = true;
                return RedirectToCurrentUmbracoPage();
            }
    
        }
    }
    

    I have seen this topics about routing for controllers which I didn't get properly.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 02, 2017 @ 10:23
    Alex Skrypnyk
    0

    Hi pat

    I think the problem is with action of form, can you check "action" attribute of your form?

    Thanks

  • pat 124 posts 346 karma points
    Feb 02, 2017 @ 11:24
    pat
    0

    hi this is my form

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<myumbracoMVC.Models.ContactUsModel>
    @using Umbraco.Web
    @{
        Html.EnableClientValidation(true);
        Html.EnableUnobtrusiveJavaScript(true);
    }
    
    @if (Convert.ToBoolean(TempData["IsSuccessful"]))
    {
        <h2>Request Sent</h2>
        <p>Thank you for contacting us, we will get back to you soon.</p>
    
    }
    else
    {
        using (Html.BeginUmbracoForm("Submit", "ContactUsController"))
        {
    
            @Html.ValidationSummary(true)
            @Html.AntiForgeryToken()
            <br/>
            @Html.TextBoxFor(model => model.Name, new { placeholder = "Your Name" })
            @Html.ValidationMessageFor(model => model.Name)
            <br/>
            @Html.TextBoxFor(model => model.Email, new { placeholder = "Email" })
            @Html.ValidationMessageFor(model => model.Email)
            <br/>
            @Html.TextBoxFor(model => model.Telephone, new { placeholder = "Telephone" })
            @Html.ValidationMessageFor(model => model.Telephone)
            <br/>
            @Html.TextAreaFor(model => model.Message, new { placeholder = "Message" })
            @Html.ValidationMessageFor(model => model.Message)
            <br/>
            <input type="submit" value="Submit" />
        }
    
    
    }
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 02, 2017 @ 15:47
    Alex Skrypnyk
    100

    Hi Pat

    Try to use this code:

    @using (Html.BeginUmbracoForm<ContactUsController>("Submit", FormMethod.Post))
                        {
        }
    

    I hope it will help you

    Thanks,

    Alex

  • John Bergman 483 posts 1132 karma points
    Feb 02, 2017 @ 15:45
    John Bergman
    0

    There is a nuget package called routedebugger that is pretty helpful in identifying issues like this.

  • Micha Somers 134 posts 597 karma points
    Feb 03, 2017 @ 11:46
    Micha Somers
    0

    Can you change your Index method to see what happens when you use:

    return PartialView("~/views/partials/ContactUs.cshtml", new ContactUsModel());
    

    If that does not work either, can you show the code of the macro's MacroPartials view?

  • pat 124 posts 346 karma points
    Feb 03, 2017 @ 14:07
    pat
    0

    hi Micha, I have tried above and my partial View Macro File is ready as below.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
        @using myumbracoMVC.Models
    @{ Html.RenderPartial("~/Views/Partials/ContactUs.cshtml", new ContactUsModel());}
    

    I have created macro and set above script. still get same error.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 03, 2017 @ 14:34
    Alex Skrypnyk
    0

    Hi Pat

    Did you build you solution?

    Where is your controller code placed?

    Is it website?

  • pat 124 posts 346 karma points
    Feb 06, 2017 @ 09:31
    pat
    0

    yes build visual studio project add umbraco dlls and then copy over project dll to web site bin folder and view in to Partials folder and macro view in macro Partials folder ....

    I do not want to create too many templates for each custom forms that I need to add to sites as I have old version 4 site with customer portal where I have login system, account management, shopping cart , quote tool and many more .... all in web forms, so I was looking at possibility of converting them in to MVC and recreate version 7 site.

    but this is not near possible as I cannot resolve this route table issue for 4 days ...... feel like pulling all my hair out :(

  • Micha Somers 134 posts 597 karma points
    Feb 03, 2017 @ 16:07
    Micha Somers
    0

    If you want to call the surface controller's Index method, the partial view macro page should look like this:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @Html.Action("Index", "ContactUs")
    
  • pat 124 posts 346 karma points
    Feb 06, 2017 @ 09:37
    pat
    0

    Hi Mica, I have tried Index method like that then form not rendering at all

  • pat 124 posts 346 karma points
    Feb 06, 2017 @ 10:09
    pat
    0

    Hi Alex, you were correct in earlier, I need to call contactuscontroller in view beginumbracoform

    but I was struggling as I just tried ContactUsController in

    @using (Html.BeginUmbracoForm<ContactUsController>("Submit", FormMethod.Post))
    

    As I have copied .dll I need give full path for it ... as below

       using (Html.BeginUmbracoForm<myumbracoMVC.Controllers.ContactUsController>("Submit", "ContactUsController",FormMethod.Post))   
    

    just released this after reading Shannon Deminick reply on below post

    https://our.umbraco.org/forum/developers/api-questions/38662-v6-Could-not-find-a-Surface-controller-route-error?p=0

    thanks for your support big relief :)

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 06, 2017 @ 12:21
    Alex Skrypnyk
    0

    Hi Pat

    I'm really glad to help you. Have a nice day!

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft