I am new to Umbraco and ASP.NET MVC and I am working on a contact us form in Umbraco 7.
I created the controller and and the view but i am getting the error
Could not find a Surface controller route in the RouteTable for controller name ContactUsSurfaceController
My model:
public class ContactUs
{
/// <summary>
///
/// </summary>
public string Name { get; set; }
/// <summary>
///
/// </summary>
public string Company { get; set; }
/// <summary>
///
/// </summary>
public string Email { get; set; }
/// <summary>
///
/// </summary>
public string Tel { get; set; }
/// <summary>
///
/// </summary>
public string Intrested { get; set; }
/// <summary>
///
/// </summary>
public string Message { get; set; }
}
My controller
public class ContactUsSurfaceController : SurfaceController
{
[HttpPost]
public ActionResult Contact(ContactUs model)
{
if(ModelState.IsValid)
{
var sb = new StringBuilder();
sb.AppendFormat("<p>name: {0}</p>", model.Name);
sb.AppendFormat("<p>name: {0}</p>", model.Company);
sb.AppendFormat("<p>name: {0}</p>", model.Email);
sb.AppendFormat("<p>name: {0}</p>", model.Tel);
sb.AppendFormat("<p>name: {0}</p>", model.Intrested);
sb.AppendFormat("<p>name: {0}</p>", model.Message);
umbraco.library.SendMail("[email protected]", "[email protected]", "Contact Us", sb.ToString(), true);
return RedirectToCurrentUmbracoPage();
}
return JavaScript("alert('error')");
}
}
}
My view for this model:
@model Umbraco.AddingValues.Web.Model.ContactUs
@using (Html.BeginUmbracoForm("Contact", "ContactUsSurfaceController", null, new { @class = "contact-form" }))
{
@Html.ValidationSummary(true)
<div>
@Html.LabelFor(x => x.Name)
@Html.TextBoxFor(x => x.Name)
@Html.ValidationMessageFor(x => x.Name)
@Html.LabelFor(x => x.Email)
@Html.TextAreaFor(x => x.Email)
@Html.ValidationMessageFor(x => x.Email)
@Html.LabelFor(x => x.Tel)
@Html.TextBoxFor(x => x.Tel)
@Html.ValidationMessageFor(x => x.Tel)
@Html.LabelFor(x => x.Intrested)
@Html.TextBoxFor(x => x.Intrested)
@Html.ValidationMessageFor(x => x.Intrested)
@Html.LabelFor(x => x.Message)
@Html.TextBoxFor(x => x.Message)
@Html.ValidationMessageFor(x => x.Message)
</div>
<input type="submit" value="Send Message" class="btn-accept" />
}
and I call this in another view like this
@Html.Action("~/Views/Partials/ContactForm.cshtml")
Please help me to resolve the error I get
Could not find a Surface controller route in the RouteTable for controller name ContactUsSurfaceController
@using (Html.BeginUmbracoForm("Contact", "ContactUsSurfaceController", null..
be"ContactUs"
or "ContactUsSurface"
? – user3559349