我是MVC的新手,我已经按照教程构建联系表单页面,但收到此错误消息:名称空间名称'模型'不存在
Controller - ContactSurfaceController.cs
namespace test.Controllers {
public class ContactSurfaceController : SurfaceController
{
[HttpPost]
public ActionResult Contact(ContactModel model)
{
if (ModelState.IsValid)
{
var sb = new StringBuilder();
sb.AppendFormat("<p>Meddelande: {0}</p>", model.Message);
sb.AppendFormat("<p>Namn: {0}</p>", model.Name);
sb.AppendFormat("<p>E-post: {0}</p>", model.Email);
sb.AppendFormat("<p>Telefon: {0}</p>", model.Phone);
library.SendMail("noreply@test.se", "info@test.se", model.Subject, sb.ToString(), true);
return RedirectToUmbracoPage(model.ThankYouPage);
}
return CurrentUmbracoPage();
}
}
}
模型 - ContactModel.cs
namespace test.Models
{
public class ContactModel
{
[Required]
[DisplayName("Ärende")]
public string Subject { get; set; }
[Required]
[DisplayName("Namn")]
public string Name { get; set; }
[Required]
[DisplayName("E-post")]
public string Email { get; set; }
[DisplayName("Telefon")]
public string Phone { get; set; }
[Required]
[DisplayName("Ärende")]
public string Message { get; set; }
public int ThankYouPage { get; set; }
}
}
部分视图 - ContactForm.cshtml
@model test.Models.ContactModel
@using (Html.BeginUmbracoForm("Contact", "ContactSurface", null, new {@class = "contact-form" }))
{
@Html.ValidationSummary(true)
<div>
@Html.LabelFor(x => x.Subject)
@Html.TextBoxFor(x => x.Subject)
@Html.ValidationMessageFor(x => x.Subject)
@Html.LabelFor(x => x.Message)
@Html.TextAreaFor(x => x.Message)
@Html.ValidationMessageFor(x => x.Message)
@Html.LabelFor(x => x.Name)
@Html.TextBoxFor(x => x.Name)
@Html.ValidationMessageFor(x => x.Name)
@Html.LabelFor(x => x.Phone)
@Html.TextBoxFor(x => x.Phone)
@Html.ValidationMessageFor(x => x.Phone)
@Html.LabelFor(x => x.Email)
@Html.TextBoxFor(x => x.Email)
@Html.ValidationMessageFor(x => x.Email)
@Html.HiddenFor(x => x.ThankYouPage)
</div>
<input type="submit" value="Skicka" class="btn-accept" />
}
就在这里,我在第一行收到错误消息 查看 - Contact.cshtml
@using test.Models
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "uBlogsyBaseSite.cshtml";
}
@Html.Partial("ContactForm", new ContactModel { ThankYouPage = Model.Content.GetPropertyValue<int>("thankYouPage") })
我错过了什么?
我真的需要帮助,感谢任何帮助。
谢谢, 纳斯
答案 0 :(得分:3)
您在哪里存储表面控制器代码和型号代码?
它应存储在app_code或单独的DLL中。