I need that I do not see the list of all the people when I enter the index view, but when I search the search engine I see the results. Thank you in advance.
Controller
public ActionResult Index(string option, string search)
{
//if a user choose the radio button option as Subject
if (option == "Cedula")
{
//Index action method will return a view with a student records based on what a user specify the value in textbox
return View(db.tg04Personas.Where(x => x.personaCedula == search || search == null).ToList());
}
else if (option == "Ruc")
{
return View(db.tg04Personas.Where(x => x.personaRuc == search || search == null).ToList());
}
else
{
return View(db.tg04Personas.Where(x => x.personaNombre.StartsWith(search) || search == null).ToList());
}
}
View
@using (Html.BeginForm("Index", "tg04Personas", FormMethod.Get))
{
//the following are search options
<b> Buscar por: </b>
@Html.RadioButton("option", "Nombre") <text>Nombre</text>
@Html.RadioButton("option", "Cedula") <text> Cédula </text>
@Html.RadioButton("option", "Ruc")<text>Ruc</text>
@Html.TextBox("search")
<input type = "submit" name = "submit" value = "Search"/>
}
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.personaCedula)
</th>
<th>
@Html.DisplayNameFor(model => model.personaPasaporte)
</th>
<th>
@Html.DisplayNameFor(model => model.personaRuc)
</th>
<th>
@Html.DisplayNameFor(model => model.personaNombre)
</th>
<th>
@Html.DisplayNameFor(model => model.personaFechaNacimiento)
</th>
<th>
@Html.DisplayNameFor(model => model.personaSexo)
</th>
<th>
@Html.DisplayNameFor(model => model.personaEstadoCivil)
</th>
<th>
@Html.DisplayNameFor(model => model.personaNacionalidad)
</th>
<th>
@Html.DisplayNameFor(model => model.personaTelefonoMovil)
</th>
<th>
@Html.DisplayNameFor(model => model.personaCorreo)
</th>
<th>
@Html.DisplayNameFor(model => model.formaTratar)
</th>
<th>
@Html.DisplayNameFor(model => model.personaReferente)
</th>
<th>
@Html.DisplayNameFor(model => model.profesion)
</th>
<th>
@Html.DisplayNameFor(model => model.actividadEconomica)
</th>
<th>
@Html.DisplayNameFor(model => model.empresaTrabajo)
</th>
<th>
@Html.DisplayNameFor(model => model.tipoEmpresa)
</th>
<th>
@Html.DisplayNameFor(model => model.nombreComercial)
</th>
<th>
@Html.DisplayNameFor(model => model.paginaWeb)
</th>
<th>
@Html.DisplayNameFor(model => model.tipoIdRepresentante)
</th>
<th>
@Html.DisplayNameFor(model => model.identificacionRepresentante)
</th>
<th>
@Html.DisplayNameFor(model => model.nombreRepresentante)
</th>
<th>
@Html.DisplayNameFor(model => model.personaTipo)
</th>
<th>
@Html.DisplayNameFor(model => model.usuarioCreacion)
</th>
<th>
@Html.DisplayNameFor(model => model.fechaModificacion)
</th>
<th>
@Html.DisplayNameFor(model => model.horaModificacion)
</th>
<th>
@Html.DisplayNameFor(model => model.usuarioModificacion)
</th>
<th>
@Html.DisplayNameFor(model => model.fechaCreacion)
</th>
<th>
@Html.DisplayNameFor(model => model.horaCreacion)
</th>
<th>
@Html.DisplayNameFor(model => model.lugarNacimiento)
</th>
<th>
@Html.DisplayNameFor(model => model.progCreacion)
</th>
<th>
@Html.DisplayNameFor(model => model.esRif)
</th>
<th>
@Html.DisplayNameFor(model => model.personaCategoria)
</th>
<th></th>
</tr>
@if (Model.Count() == 0)
{ <tr>
<td colspan = "3" > No se encontraron resultados </td>
</tr>
}
else
{
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.personaCedula)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaPasaporte)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaRuc)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaNombre)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaFechaNacimiento)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaSexo)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaEstadoCivil)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaNacionalidad)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaTelefonoMovil)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaCorreo)
</td>
<td>
@Html.DisplayFor(modelItem => item.formaTratar)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaReferente)
</td>
<td>
@Html.DisplayFor(modelItem => item.profesion)
</td>
<td>
@Html.DisplayFor(modelItem => item.actividadEconomica)
</td>
<td>
@Html.DisplayFor(modelItem => item.empresaTrabajo)
</td>
<td>
@Html.DisplayFor(modelItem => item.tipoEmpresa)
</td>
<td>
@Html.DisplayFor(modelItem => item.nombreComercial)
</td>
<td>
@Html.DisplayFor(modelItem => item.paginaWeb)
</td>
<td>
@Html.DisplayFor(modelItem => item.tipoIdRepresentante)
</td>
<td>
@Html.DisplayFor(modelItem => item.identificacionRepresentante)
</td>
<td>
@Html.DisplayFor(modelItem => item.nombreRepresentante)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaTipo)
</td>
<td>
@Html.DisplayFor(modelItem => item.usuarioCreacion)
</td>
<td>
@Html.DisplayFor(modelItem => item.fechaModificacion)
</td>
<td>
@Html.DisplayFor(modelItem => item.horaModificacion)
</td>
<td>
@Html.DisplayFor(modelItem => item.usuarioModificacion)
</td>
<td>
@Html.DisplayFor(modelItem => item.fechaCreacion)
</td>
<td>
@Html.DisplayFor(modelItem => item.horaCreacion)
</td>
<td>
@Html.DisplayFor(modelItem => item.lugarNacimiento)
</td>
<td>
@Html.DisplayFor(modelItem => item.progCreacion)
</td>
<td>
@Html.DisplayFor(modelItem => item.esRif)
</td>
<td>
@Html.DisplayFor(modelItem => item.personaCategoria)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.personaNumero }) |
@Html.ActionLink("Details", "Details", new { id = item.personaNumero }) |
@Html.ActionLink("Delete", "Delete", new { id = item.personaNumero })
</td>
</tr>
}
}