【发布时间】:2016-04-01 09:21:49
【问题描述】:
我正在使用 ASP.net MVC 5 和 Razor Engine。我想创建一个页面来注册用户。我为我的用户实体创建了一个模型和元数据模型。我所有的代码都在这里。我认为一切都很好,但我得到了这个编译错误:
Compiler Error Message: CS1061: 'NP1.ViewModels.RegisterVM' does not contain a definition for 'UserEmail' and no extension method 'UserEmail' accepting a first argument of type 'NP1.ViewModels.RegisterVM' could be found (are you missing a using directive or an assembly reference?)
谁能帮我解决一下?
控制器
[HttpGet]
public ActionResult Register()
{
RegisterVM vm = new RegisterVM();
vm.UserAddress = "";
vm.UserBirthDate = DateTime.Now;
vm.UserCellPhone = "";
vm.UserEmail = "";
vm.UserFirstName = "";
vm.UserGender = "";
vm.UserID = 1;
vm.UserImage = "";
vm.UserLastName = "";
vm.UserPassWord = "";
vm.UserStatus = 1;
vm.UserTell = "";
return View(vm);
}
注册虚拟机
public List<SocialNetwork> SocialNetworks { get; set; }
public List<Footer> Footers { get; set; }
public List<FooterMenu> FooterMenus { get; set; }
public List<User> Users { get; set; }
Register.cs
@model NP1.ViewModels.RegisterVM
@{
ViewBag.Title = "Register";
}
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>User</h4>
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(model => model.UserEmail, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserEmail)
@Html.ValidationMessageFor(model => model.UserEmail)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserFirstName, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserFirstName)
@Html.ValidationMessageFor(model => model.UserFirstName)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserLastName, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserLastName)
@Html.ValidationMessageFor(model => model.UserLastName)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserPassWord, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserPassWord)
@Html.ValidationMessageFor(model => model.UserPassWord)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserCellPhone, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserCellPhone)
@Html.ValidationMessageFor(model => model.UserCellPhone)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserTell, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserTell)
@Html.ValidationMessageFor(model => model.UserTell)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserImage, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserImage)
@Html.ValidationMessageFor(model => model.UserImage)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserAddress, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserAddress)
@Html.ValidationMessageFor(model => model.UserAddress)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserStatus, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserStatus)
@Html.ValidationMessageFor(model => model.UserStatus)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserBirthDate, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserBirthDate)
@Html.ValidationMessageFor(model => model.UserBirthDate)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserGender, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserGender)
@Html.ValidationMessageFor(model => model.UserGender)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
【问题讨论】:
标签: asp.net-mvc razor model compiler-errors asp.net-mvc-5