字段验证错误 - TExt当填充文本字段时,危险即将出现

时间:2015-08-13 16:03:51

标签: html asp.net-mvc razor

所以创建我的注册页面一切都很顺利但是当我添加密码并确认密码并对其进行测试时,我最终得到的密码字段留空了错误mmessage,即使我填写了文本字段并满足密码要求

我不知道为什么会这样。我的MVC 5程序的哪一部分会导致这是真的?

这是我的控制器:

    [Authorize(Roles = "Admin")]
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "MerchantID,MerchantName,State,City,StreetAddress,zip,phoneNumber,email, website")] Merchant merchant)
{

    if (ModelState.IsValid)
    {
        var _context = new ApplicationDbContext();
        var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(_context));
        //code that I am trying to implement to add to merhcant role
        var user = new ApplicationUser { UserName = merchant.MerchantName, Email = merchant.email };
        var result = await UserManager.CreateAsync(user, merchant.Password);
        //Above code is from Register controller


        if (result.Succeeded)
        {
            await this.UserManager.AddToRoleAsync("MerchantID", "Merchant");
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
            await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
            ViewBag.Link = callbackUrl;
            return View("DisplayEmail");

        }

        AddErrors(result);

            //ASP.Net provided code, don't touch.
            db.Merchants.Add(merchant);

            db.SaveChanges();
        return RedirectToAction("Index");
    }


    return View(merchant);
}

以下是视图:

    <div class="form-group">
    @Html.LabelFor(model => model.Password, new { @class = "col-md-2 control-label" })
    <div class="col-md-10">
        @Html.PasswordFor(model => model.Password, new { @class = "form-control" })
        @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
    </div>
</div>
<div class="form-group">
    @Html.LabelFor(model => model.ConfirmPassword, new { @class = "col-md-2 control-label" })
    <div class="col-md-10">
        @Html.PasswordFor(model => model.ConfirmPassword, new { @class = "form-control" })
        @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
    </div>
</div>

以下是模型:

     [Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }

[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }

0 个答案:

没有答案