1
votes

I am trying to figure out how to get a simple Contact Form SurfaceController working. The problem is that when I try to navigate to the Contact Us page, I get a "No route in the route table matches the supplied values." error.

My surface controller:

namespace UmbracoSurface2.Controllers
{
    public class ContactFormSurfaceController : SurfaceController
    {
        public ActionResult Index()
        {
            return PartialView("ContactForm", new ContactFormViewModel());
        }
    }
}

My ContactForm partial:

@model UmbracoSurface2.Models.ContactFormViewModel

<form>
    <div class="controls controls-row">
        @Html.TextBoxFor(m => m.Name)
        @Html.TextBoxFor(m => m.Email)
    </div>
    <div class="controls">
        @Html.TextAreaFor(m => m.Message, new { rows="5" })
    </div>
    <div class="controls">
        <button id="contact-submit" type="submit" class="btn btn-primary input-medium pull-right">Submit</button>
    </div>
</form>    

and my template:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    Layout = "Master.cshtml";
}
@Html.Action("Index", "ContactFormController")

The one big difference between mine and the screencasts and examples I've found is that I'm using Visual Studio 2013 so the ASP.NET Website template has a newer version of MVC which I had to remove to get the UmbracoCms NuGet package to install. I also tried it without adding MVC to the project at the beginning.

Any help/suggestions would be appreciated,

Jason

1
SurfaceControllers are ONLY for user interacting. So for example a post from a form. You have to use RenderMvcController. our.umbraco.org/documentation/Reference/Mvc/custom-controllersMorten OC
I'm not sure how what I did isn't user interaction, especially since it's the exact example used by the Umbraco team. Anyway, I've posted the solution below.Jason

1 Answers

2
votes

Okay, as per Dan's answer here on the Umbraco forum, the problem was a dumb mistake on my part. The @Html.Action line in the template should be:

@Html.Action("Index", "ContactFormSurface")

Jason