Search in visual studio

Asked

Viewed 55 times

0

I’m making a web project in the basic visual as I do so I can filter a code of type int and only show the clients with the code typed?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Nac.Models;

namespace Nac.Controllers
{
    public class ClienteController : Controller
    {
        // GET: Cliente
        public ActionResult Principal()
        {
            return View();
        }
        public ActionResult Cadastrar()
        {
            return View();
        }
        public ActionResult Buscar()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Cadastrar(Cliente c)
        {
            if (ModelState.IsValid)
            {
                Estoque e = Estoque.Instance();

                e.incluirCliente(c);

                return RedirectToAction("Listar");
            }

            return View(c);
        }

        public ActionResult Listar()
        {
            IEnumerable<Cliente> clientes = Estoque.Instance().listarClientes();
            return View(clientes);
        }

        public ActionResult Excluir(int id)
        {
            Estoque.Instance().excluirCliente(id);
            return RedirectToAction("Listar");
        }

        public ActionResult Editar(int id)
        {
            Cliente c = Estoque.Instance().listarCliente(id);
            return View("Cadastrar", c);
        }

        [HttpPost]
        public ActionResult Editar(Cliente c)
        {
            Estoque.Instance().alterarCliente(c);
            return RedirectToAction("Listar");
        }



    }
}
  • without making any code?

  • Hello, post the code you already have and the question concerning it.

1 answer

0

  1. Create an Action that takes an int variable as a parameter.
  2. Create a method to filter clients and pass the variable provided in Action as parameters.
  3. Return found customers to your View.

Example:

public ActionResult Buscar(int id)
{
    IEnumerable<Cliente> clientes = BuscarClientesPorId(id);
    return View(clientes);
}

Browser other questions tagged

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