Я создаю приложение MVC4, но ни одна из следующих форм проверки не работает, кроме электронной почты ID. имя пользователя и пароли, которые не соответствуют минимальным требованиям, все еще могут быть зарегистрированы. Регистрация становится купольной, даже если пароль и подтверждающий пароль не совпадают. Может кто-нибудь помочь, пожалуйста?
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web;
namespace ReadingCat.Models
{
public class User
{
public User()
{
File = new List<HttpPostedFileBase>();
}
public int userid { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength
= 6)]
public string username { get; set; }
[Required]
[EmailAddress(ErrorMessage = "Please enter a valid email ID")]
public string useremail { get; set; }
public string bio { get; set; }
[Required]
[StringLength(10, MinimumLength = 3)]
[DataType(DataType.Password)]
[Display(Name = "password")]
public string password { get; set; }
[DataType(DataType.Password)]
[Compare("password", ErrorMessage = "The password and confirm password do not match")]
public string confirmPassword { get; set; }
public int isAdmin { get; set; }
public List<HttpPostedFileBase> File { get; set; }
public string paths { get; set; }
}
}
Вот код просмотра
@model ReadingCat.Models.User
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Register1</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Sign Up Form by Colorlib</title>
<!-- Font Icon -->
<link rel="stylesheet" href="fonts/material-icon/css/material-design-iconic-
font.min.css">
<!-- Main css -->
<link rel="stylesheet" href="~/css/register.css">
</head>
<body>
<div class="main">
<div class="container">
<div class="book-content">
<div class="book-image">
<img class="book-img" src="~/images/register.gif" alt="">
</div>
<div class="book-form">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<form id="book-form">
<h2>Register Now!</h2>
<hr />
@Html.ValidationSummary(true, "", new { @class =
"text-danger" })
<div class="form-group form-input">
@Html.LabelFor(model => model.username,
htmlAttributes: new { @class = "register.css" })
<div class="col-md-10">
@Html.EditorFor(model => model.username, new
{ htmlAttributes = new { @class = "register.css" } })
@Html.ValidationMessageFor(model =>
model.username, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group form-input">
@Html.LabelFor(model => model.useremail,
htmlAttributes: new { @class = "register.css" })
<div class="col-md-10">
@Html.EditorFor(model => model.useremail,
new { htmlAttributes = new { @class = "register.css" } })
@Html.ValidationMessageFor(model =>
model.useremail, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.password,
htmlAttributes: new { @class = "register.css" })
<div class="col-md-10">
@Html.PasswordFor(model => model.password,
new { htmlAttributes = new { @class = "register.css" } })
@Html.ValidationMessageFor(model =>
model.password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.confirmPassword,
htmlAttributes: new { @class = "register.css" })
<div class="col-md-10">
@Html.PasswordFor(model =>
model.confirmPassword, new { htmlAttributes = new { @class = "register.css"
} })
@Html.ValidationMessageFor(model =>
model.confirmPassword, "", new { @class = "text-danger" })
</div>
</div>
<br />
<div class="form-submit">
<input type="submit" value="Submit"
class="submit" id="submit" name="submit" />
</div>
</form>
}
</div>
</div>
</div>
</div>
<!-- JS -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>