【发布时间】:2015-02-13 23:55:56
【问题描述】:
当我在浏览器中转到视图用户/添加时,我收到以下消息 -
编译器错误消息:CS0234:命名空间“CRM.Core.Models”中不存在类型或命名空间名称“UserModel”(您是否缺少程序集引用?)
任何想法我哪里出错了?
查看
@model CRM.Core.Models.UserModel
@{
ViewBag.Title = "Add";
}
<h2>Add</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>UserModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.EmployeeNumber)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.EmployeeNumber)
@Html.ValidationMessageFor(model => model.EmployeeNumber)
</div>
</fieldset>
}
用户控制器
public ActionResult Add()
{
return View();
}
[HttpPost]
public ActionResult Add(UserModel model)
{
if (ModelState.IsValid)
{
_userService.Add(model);
}
return View(model);
}
UserModel.cs
namespace CRM.Core.Models
{
public class UserModel : IUserModel
{
[DisplayName("Employee Number")]
public int EmployeeNumber { get; set; }
}
}
【问题讨论】:
-
将
@using CRM.Core.Models;添加到您的视图有帮助吗? -
刚刚试过了,还是不行
-
假设项目已编译并且类是公共的...尝试使用
global::CRM.Core.Models.UserModel,以防万一您有一些名称重复的命名空间... -
如果您的模型在单独的程序集中,请确保正确构建并正确引用它。
-
所有似乎都被引用了 好的,并且已经完成了重建、清理等工作。@AdrianoRepetti 你的建议会去哪里?以前从未见过。
标签: c# asp.net-mvc