[英]ASP.NET MVC display for
I created an ASP.NET MVC4 project with authentication.我创建了一个带有身份验证的 ASP.NET MVC4 项目。 When I run my app I get an error:
当我运行我的应用程序时,我收到一个错误:
System.NullReferenceException
System.NullReferenceException
on the 17th line in file Views/Accounts/Register.在文件 Views/Accounts/Register 的第 17 行。 How can I resolve it?
我该如何解决?
@model ImArtistApp.Models.RegisterViewModel
@{
ViewBag.Title = "Регистрация";
}
<h2>@ViewBag.Title.</h2>
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Создание новой учетной записи.</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
// Error here
@Html.DisplayFor(m => m.Email, new { @class = "form-control" })
</div> ....
Code of model: model代码:
public class RegisterViewModel
{
[Required]
[EmailAddress]
[DataType(DataType.Text)]
[Display(Name = "Адрес электронной почты")]
[UIHint("String")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "Значение {0} должно содержать не менее {2} символов.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Пароль")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Подтверждение пароля")]
[Compare("Password", ErrorMessage = "Пароль и его подтверждение не совпадают.")]
public string ConfirmPassword { get; set; }
}
Do you return the Model to the controller in the Register action?您是否在注册操作中将 Model 返回到 controller?
public ActionResult Register()
{
var model = new RegisterViewModel();
return View(model);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.