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

Asked

Viewed 151 times

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")



}

inserir a descrição da imagem aqui

I need to make the query by code or address according to the client’s choice. Does anyone have a solution for this ?

2 answers

0

In my opinion, the best way to do a search is by using Datatable. In addition to already having a search box where you search for all columns, you can configure and create boxes to search for separate columns.

Here is the documentation and a great example for this: https://datatables.net/examples/api/regex.html

Datatable facilitates the lives of many programmers, whenever I need I use.

0

How you need to search by code 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")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.