我是Umbraco和ASP.NET MVC的新手,我正在Umbraco 7中联系我们。
我创建了控制器和视图,但我收到了错误
无法在RouteTable中找到控制器名称ContactUsSurfaceController
的Surface控制器路由
我的模特:
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")
请帮我解决我收到的错误
无法在RouteTable中找到控制器名称ContactUsSurfaceController
的Surface控制器路由
答案 0 :(得分:1)
更改
@using (Html.BeginUmbracoForm("Contact", "ContactUsSurfaceController", null, new { @class = "contact-form" }))
要:
@using (Html.BeginUmbracoForm<ContactUsSurfaceController>("Contact"))