Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/05/2017, 06:26
Juan228
 
Fecha de Ingreso: febrero-2008
Mensajes: 65
Antigüedad: 16 años, 2 meses
Puntos: 0
Problemas con validaciones con Razor

Hola! Les muestro:

Mi Clase:
Código C++:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.ComponentModel.DataAnnotations;
  6.  
  7. namespace Clase6.Models
  8. {
  9.     public class Usuario
  10.     {
  11.         [Required]
  12.         [StringLength(25, MinimumLength = 3, ErrorMessage = "El nombre debe tener entre 3 y 25 letras")]
  13.         public string Nombre { set; get; }
  14.  
  15.         [Required]
  16.         [StringLength(25, MinimumLength = 3, ErrorMessage = "El apellido debe tener entre 3 y 25 letras")]
  17.         public string Apellido { set; get; }
  18.  
  19.         public Perfil Perfil { get; set; }
  20.  
  21.         [Required]
  22.         [Range(1,25, ErrorMessage = "El campo perfil es requerido")]
  23.         public int IdPerfil { get; set; }
  24.     }
  25. }

Mi Formulario:
Código C++:
Ver original
  1. @{
  2.     ViewBag.Title = "Crear";
  3.     Layout = "~/Views/_shared/_Layout.cshtml";
  4. }
  5.  
  6. @model Clase6.Models.Usuario
  7.  
  8. <form role="form" method="post">
  9.  
  10.     @Html.LabelFor(model => model.Nombre, new { @for = "txtNombre" })
  11.     @Html.TextBoxFor(model => model.Nombre, new { @class = "form-control" })
  12.     @Html.ValidationMessageFor(model => model.Nombre , "", new { @class = "text-danger" })
  13.  
  14.  
  15.     @Html.LabelFor(model => model.Apellido, new { @for = "txtApellido" })
  16.     @Html.TextBoxFor(model => model.Apellido, new { @class = "form-control" })
  17.     @Html.ValidationMessageFor(model => model.Apellido)
  18.  
  19.  
  20.     @Html.Label("Seleccionar Perfil", new { @for = "txtIdPerfil" })
  21.     @Html.DropDownListFor(model => model.IdPerfil, new SelectList(ViewBag.perfiles, "Id", "Descripcion"), new { @class = "form-control" })
  22.     @Html.ValidationMessageFor(model => model.IdPerfil)
  23.    
  24.     <br />  
  25.     <button type="submit" class="btn btn-primary btn-block">Enviar</button>
  26.  
  27. </form>


Alguno logra darse cuenta por que no me esta funcionando la validacion? Me estoy olvidando de algo? Gracias!