0

The application has tabs: All, Computers, Telephones

The product search should depend on the given tab, that is if we browse the phone tab, only the phones should show us when searching.

Classes:

Product:        

 

public int Id {get; set; }
        public string Name {get; set; }
        public decimal Price {get; set; }
        public int CategoryId {get; set; }

Category:        

 

public int Id {get; set; }
        public string Name {get; set; }

View:

 @using (Html.BeginForm ("Index", "Product", FormMethod.Get, null))
    {
    div class="input-group"
    input id="search" type="search" class="form-control" name="search" 
    placeholder= "Search ...">
    button class="btn btn-default">Search button>
    div>

    } 

 

                              

biaaly13
  • 3
  • 4

1 Answers1

0

Index Action of Product Controller should receive CategoryId also

public ActionResult Index(string search, int categoryId)
{
}

Form should send categoryId and hidden field

@using (Html.BeginForm ("Index", "Product", FormMethod.Get, null))
{
  <input id="search" type="text" name="search">
  <input type="hidden" id="categoryId" value="1" name="search">
  <button type="submit">Search</button>    
} 

Detect tab change and change categoryId value

Ex: with Jquery

$("#categoryId").val(2);
Ivan Valadares
  • 869
  • 1
  • 8
  • 18
  • 1
    Thanks for answers guys! I did it differently. In the controller, the category that was called from the bookmark I added to ViewModel was sent back to the view. From the object I added to the hidden input. – biaaly13 Dec 08 '18 at 10:41