How to use two checkboxes in a C # mvc view to choose the type of query?

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 customer's choice. Does anyone have a solution for this?

    
asked by anonymous 17.09.2017 / 16:14

2 answers

0

In my opinion, the best way to do a search is by using DataTable. In addition, you already have a search box where you search for all columns, you can set up and create boxes to search for different columns.

Here's the documentation and a great example for this: link

DataTable makes life easier for many programmers, whenever I need them I use.

    
17.09.2017 / 19:05
0

As you need to search for OR address, you will need to use RadioBox or ComboBox:

RadioBox

Codigo:   @Html.RadioButton("Pesquisa","Codigo")  
Endereco: @Html.RadioButton("Pesquisa","Endereco") 

ComboBox

@Html.DropDownList("Pesquisa")
    
18.09.2017 / 14:59