Validation with data annotations ASP.NET MVC works but does not display message

0

Good evening! I'm having a problem in my project where I'm trying to validate with date annotations and it's working, I just register in the database if I answer the validations, but the problem is that the messages I put to display along the date annotations do not work and I do not have idea of why this is happening, I have already looked at several codes and is identical but my valid but does not display the message. Someone help me please!

    
asked by anonymous 12.08.2017 / 02:17

2 answers

1

I was able to find the problem, in the @Html.ValidationSummary () I put @Html.ValidationSummary (true), have to stay alone @ Html.ValidationSummary (), thanks for the help

    
12.08.2017 / 18:01
0

Controller:

using System;

using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ProjectInfo.ViewModels; using ProjectDeInovacao.Models; using ProjectInfo.Classes;

namespace ProjectInnovative.Controllers {     public class HomeController: Controller     {

    CadastroBLL bll = new CadastroBLL();
    [HttpGet]
    public ActionResult Login()
    {
        return View();
    }
    // instancia  e  manda  valores  para  variaveis 
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Login(Cadastro model)
    {
        if (ModelState.IsValid)
        {

            ViewData["Nome"] = model.Nome;
            ViewData["Email"] = model.Email;
            ViewData["Senha"] = model.Senha;
            bll.cadastrar(model);
            ModelState.Clear();
            return View(model);
        }
        else
        {
            return View("Login");
        }

    }
    public ActionResult Index()
    {
        ViewBag.Title = "Amorelli - Home";
        return View();
    }
    public ActionResult Carrinho()
    {
        ViewBag.Title = "Amorelli - Carrinho";
        return View();
    }
}

}

Model:

using System;

using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations;

namespace ProjectInnovative.Models {     public class Registration     {         private string name;         [Required (ErrorMessage="Required to enter name")]         public string Name         {             get {return name; }             set {name = value; }         }         private string email;         [Required (ErrorMessage="Required E-mail")]         [RegularExpression (". + \ @. + \ .. +", ErrorMessage="The E-mail entered is not valid")]         public string Email         {             get {return email; }             set {email = value; }         }         private string password;         [Required (ErrorMessage="Required to enter a password")]         [DataType (DataType.Password)]         [StringLength (20, MinimumLength = 8)]         public string Password         {             get {return password; }             set {password = value; }         }     } }

View: @modelModels.CadastroDevelopment.model @ {     ViewBag.Title="Amorelli - Login"; }

/*PARA VALIDAÇÃO DOS HELPERS*/
.field-validation-error {
    color: #f00;
}

.field-validation-valid {
    display: none;
}

.input-validation-error {
    border: 1px solid #f00;
    background-color: #fee;
}

.validation-summary-errors {
    font-weight: bold;
    color: #b94a48;
}

.validation-summary-valid {
    display: none;
}

                                                                                          

Log in to your account

                                                                                                                                                         Keep me connected                                                  Login                                                                                 OR                                                                                     

Sign up!

                    @using (Html.BeginForm ("Login", "Home"))                     {                         @Html.AntiForgeryToken ();                                                      @Html.TextBoxFor (Model => Model.Name, new {id="Name", placeholder="Full Name"})                                                                               @ Html.TextBoxFor (Model => Model.Email, new {id="Email1", placeholder="Email"})                                                                               @ Html.TextBoxFor (Model => Template.Senha, new {id="Password1", placeholder="Password", type="password"})                                                  Register                         Home                         @Html.ValidationSummary (false, "Please correct the errors below:")                     }                                            

(form login still being created)

    
14.08.2017 / 19:13