1
Controller.cs
public ActionResult pesquisarCliente(string _codigo)
{
var r = db.Pedido.AsQueryable();
if (!string.IsNullOrEmpty(_codigo))
{
r = r.Where(n => n.Cliente.Contains(_codigo));
r.OrderBy(n => n.Cliente);
}
if (Request.IsAjaxRequest())
{
return PartialView("_Pedido",r.ToList());
}
return View(r.ToList());
}
_Pedito.cshtml - > PartialView
@model IEnumerable<DiskCaçamba.Pedido>
<div id="divlistapedido">
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Data)
</th>
<th>
@Html.DisplayNameFor(model => model.Cliente)
</th>
<th>
@Html.DisplayNameFor(model => model.EnderecoEntrega)
</th>
<th>
@Html.DisplayNameFor(model => model.Cacamba1.Descricao)
</th>
<th>
@Html.DisplayNameFor(model => model.Loja1.NomeLoja)
</th>
<th>
@Html.DisplayNameFor(model => model.Motorista1.NomeMotorista)
</th>
<th>
@Html.DisplayNameFor(model => model.Situacao.Descricao)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Data)
</td>
<td>
@Html.DisplayFor(modelItem => item.Cliente)
</td>
<td>
@Html.DisplayFor(modelItem => item.EnderecoEntrega)
</td>
<td>
@Html.DisplayFor(modelItem => item.Cacamba1.Descricao)
</td>
<td>
@Html.DisplayFor(modelItem => item.Loja1.NomeLoja)
</td>
<td>
@Html.DisplayFor(modelItem => item.Motorista1.NomeMotorista)
</td>
<td>
@Html.DisplayFor(modelItem => item.Situacao.Descricao)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.IdPedido }) |
@Html.ActionLink("Details", "Details", new { id = item.IdPedido }) |
@Html.ActionLink("Delete", "Delete", new { id = item.IdPedido })
</td>
</tr>
}
</table>
</div>
View PesquisarCliente
@model IEnumerable<DiskCaçamba.Pedido>
<br />
<p>
Pesquisar codigo
@using (Ajax.BeginForm("pesquisarCliente", "Consulta", new AjaxOptions { HttpMethod = "Get", InsertionMode = InsertionMode.Replace, UpdateTargetId = "divlistapedido" }))
{
@Html.CheckBox("CbEndereço") // Preciso especificar por endereço ou cliente
@Html.Label("Endereço")
<br />
@Html.CheckBox("CbCodigo")
@Html.Label("Codigo")
<br />
@Html.TextBox("_codigo")
<input type="submit" value="Pesquisar" />
}
</p>
<br />
@Html.Partial("_Pedido", Model)
@Session Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
I need to make the query by code or address according to the client’s choice. Does anyone have a solution for this ?