简体   繁体   中英

Contact us form in ASP.NET MVC using Umbraco

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("test@test.com", "test@test.com", "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

Change

 @using (Html.BeginUmbracoForm("Contact", "ContactUsSurfaceController", null, new { @class = "contact-form" }))

To:

@using (Html.BeginUmbracoForm<ContactUsSurfaceController>("Contact"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM