Vous êtes sur la page 1sur 4

Controles Helper

1. Crear un controlador vacio y una vista

<h2>Controles Helper</h2>

@Html.Label("Ingesar Nombre : ")


<br />
@Html.TextBox("Nombre", "Juan")
<br />
@Html.Label("Ingesar Apellido : ")
<br />
@Html.TextBox("Apellido", "Leon", new { style = "background-color:red" })
<br />
@Html.Label("Direccion : ")
<br />
@Html.TextBox("Direccion", "Direccion", new { @class = "colortexto", @readonly =
"true" })
<br />
@Html.Label("Password")
<br />
@Html.Password("Password")
<br />
@Html.Label("Area de Ingreso")
<br />
@Html.TextArea("Comentario", "", 5, 50, null)
<br />
@Html.Label("Lista de Departaamentos")
<br />
@Html.DropDownList("Departamentos",new List<SelectListItem>
{
new SelectListItem{Text="Lima",Value="1",Selected=true},
new SelectListItem{Text="Ate",Value="2"},
new SelectListItem{Text="Lince",Value="3"},
},"Seleccionar Departamento")

Base de datos(crear una base en ado Entity - model)

Controlador :

public ActionResult Index1()


{
DEMOEntities2 db = new DEMOEntities2();
ViewBag.departamentos = new SelectList
(db.lista, "id", "distrito");

return View();
}

Vista :

@model Helpers01.Models.lista
@{
ViewBag.Title = "Index1";
}
<h2>Lista de Datos-Modelo</h2>
@Html.DropDownList("departamentos", "Seleccionar del Modelo")

webgrid
1.- Crear un ado entity(cliente)

2.- Crear un controlador(vacio)

3.- referenciar el model, en el controlador

4. crear un metodo
NeptunoWebEntities db = new NeptunoWebEntities();
public ActionResult Index()
{
return View(db.Clientes.ToList());
}

5. crear un vista vacia

@model List<WebGrid01.Models.Clientes>
@{
ViewBag.Title = "Index";
WebGrid wg = new WebGrid(Model);
}
<style type="text/css">
.headerStyle
{
background:#0094ff;
}
.tableStyle
{
background:#00ff90;
}
.alternateStyle{
background:#ffd800;
}

</style>

<h2>Lista de Clientes</h2>
<br />
@wg.GetHtml(
headerStyle: "headerStyle",
tableStyle: "tableStyle",
alternatingRowStyle: "alternateStyle",
columns:new[]
{
wg.Column("IdCliente",header:"Codigo"),
wg.Column("NombreContacto",header:"Cliente"),
wg.Column("Direccion",header:"Domicilio"),
wg.Column("Ciudad",header:"Ciudad"),
wg.Column("pais",header:"Origen")
})
6. regresar al controlador y crear un Nuevo metodo para la busqueda de datos

public ActionResult IndexBusqueda(string nombre)


{
IQueryable<Clientes> resultado = db.Clientes;
if (!string.IsNullOrEmpty(nombre))
{
resultado = resultado.Where
(p => p.NombreContacto.Contains(nombre));
}
return View(resultado.ToList());
}

7. crear una nueva vista

@model List<WebGrid01.Models.Clientes>
@{
ViewBag.Title = "IndexBusqueda";
WebGrid wg = new WebGrid(Model);
}
<style type="text/css">
.headerStyle {
background: #0094ff;
}

.tableStyle {
background: #00ff90;
}

.alternateStyle {
background: #ffd800;
}
</style>

@using (Html.BeginForm("IndexBusqueda", "Cliente", FormMethod.Get))


{
<fieldset>
<legend>
Buscar
</legend>
@Html.Label("LblCliente","Cliente : ")
@Html.TextBox("nombre")
<input type="submit" name="name" value="Buscar" />
</fieldset>
}

<h2>Lista de Clientes</h2>
<br />
@wg.GetHtml(
headerStyle: "headerStyle",
tableStyle: "tableStyle",
alternatingRowStyle: "alternateStyle",
columns: new[]
{
wg.Column("IdCliente",header:"Codigo"),
wg.Column("NombreContacto",header:"Cliente"),
wg.Column("Direccion",header:"Domicilio"),
wg.Column("Ciudad",header:"Ciudad"),
wg.Column("pais",header:"Origen")
})

Vous aimerez peut-être aussi