联系我们的形式在ASP.. NET MVC使用Umbraco

本文关键字:NET ASP MVC 使用 Umbraco 联系我 我们 联系 | 更新日期: 2023-09-27 18:14:51

我是新手。. NET MVC和我在Umbraco 7的联系我们的形式工作。

我创建了控制器和视图但是我得到了错误

无法在路由表中找到控制器名称ContactUsSurfaceController的表面控制器路由

我的模型:

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; }
}

我的控制器

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')");
       }
    }
}

我对这个模型的看法:

    @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" />
  } 

在另一个视图中我将其命名为

    @Html.Action("~/Views/Partials/ContactForm.cshtml")

请帮我解决我得到的错误

无法在路由表中找到控制器名称ContactUsSurfaceController的表面控制器路由

联系我们的形式在ASP.. NET MVC使用Umbraco

变化

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

:

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