7 Programación Web con .NET y C#
Transcript of 7 Programación Web con .NET y C#
Validaciones Required DisplayName MaxLength StringLength Range ScaffoldColumn HiddenInput
Validacion (cont.) Compare DataType DisplayFormat RegularExpression UIHint
Formato Cadenas{indice,alineacion:formato}
Formatos Numericos C Currency D Decimal E Exponencial F punto flotante N numero P porciento X hexadecimal
Formatos Personalizados 0 si existe numero si no cero # si existe numero sino nada . Punto decimal , separador de miles % porcentaje ; mayor a cero,menor a cero, igual
Formatos Fecha d fecha f fecha y hora g Fecha regional m Mes/dia t Hora y Año/mes
Formato fecha personalizado d,dd,ddd,dddd M,MM,MMM,MMMM H,h,hh,HH s,ss y,yy,yyyy t am/pm
Expresiones Regulares Rango
[a-z][0-9][aeiou]
Inicio ^ Fin $
Expresiones Regulares Repeticion
{x}{x,}{x,y}? * +
Agrupamiento()|
Ejemplos Numero
^[0-9]+$ Numero real
^[0-9]+?(.|,[0-9]+)$ Correo Electrónico
^([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\- ]+@([a-zA-Z0-9\- ]+\.)+([a-zA-Z0-9\-]{2,3})$
Teléfono 591-4-1234567^[0-9]{3}-[0-9]{1}-[0-9]{7}$
IP ^[0-9]{1,3}\.[0-0]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$
Validaciones Personalizadas Crear una clase que implemente
ValidationAttribute Usar Anotación AtributeUsage para
AtributteTargets.Property y Field Implementar método IsValid()
Interface ValidationAttributepublic abstract class ValidationAttribute : Attribute{ public string ErrorMessage { get; set; }
public virtual bool IsValid(object value);
protected virtual ValidationResult IsValid(object value, ValidationContext c);
public virtual string FormatErrorMessage(string name)
// otros metodos}
int size = 3; int pagina = (pagina ?? 1); return .ToPagedList(pagina, size)); @model PagedList.IPagedList<Product> @using PagedList.Mvc; @using PagedList; @Html.PagedListPager(Model, page =>
Url.Action("Index", new { page }))
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@if (Model.HasPreviousPage) { @Html.ActionLink("<<", "Index", new { page = 1}) @Html.Raw(" "); @Html.ActionLink("< Prev", "Index", new { page = Model.PageNumber - 1}) } else { @:<< @Html.Raw(" "); @:< Prev }
@if (Model.HasNextPage) { @Html.ActionLink("Next >", "Index", new { page = Model.PageNumber + 1 }) @Html.Raw(" "); @Html.ActionLink(">>", "Index", new { page = Model.PageCount}) } else { @:Next > @Html.Raw(" ") @:>> }
Configuración Cultura Web.config <globalization culture="es-BO"
uiCulture="es-BO" />