Select Suppliers by Fantasy Name

2

I have a PRODUCT registration form and there is a relationship with the SUPPLIER table, as shown in the image below:

ClickingtheSEARCHPROVIDERbuttonwilldisplaythisView

Now I need to develop a text box that when typing a value it looks for all SUPPLIERS that contains a FANTASY NAME equal to the one typed in the text box.

This Controller shows all the providers, but I only want the ones with FANTASY NAME typed in the text box:

public ActionResult Index()
    {
        try
        {
            using (SistemaDBEntities db = new SistemaDBEntities())
            {
                return View(db.Fornecedor.Where(s => s.Ativo == true).ToList());
            }
        }
        catch (Exception)
        {

            throw;
        }

    }
    
asked by anonymous 10.10.2015 / 23:10

1 answer

3

So I turned my problem around:

[HttpPost] 
public ActionResult Index(string sConsulta)
{
    var consulta = db.Fornecedor.Where(s => s.NomeFantasia.Contains(sConsulta)).ToList();
    return View(consulta);
}



@using (Html.BeginForm())
{
 <p>Digite o nome/fantasia</p>
 <input placeholder="Digite o Nome/Fantasia" type="text" name="sConsulta" id="sConsulta"  />
 <div><button type="submit">Consultar</button></div>   
}
    
17.10.2015 / 21:46