I am trying to connect the Front-end(reactjs) with the asp net core API
Front-end
- async getFilterData() {
- this.setState({ tableLoading: true });
-
-
- const TitleFIlter = document.getElementById("TitleFIlter").value
- const descriptionFilter = document.getElementById("DescriptionFilter").value
- const priceminFIlter = document.getElementById("PriceMin").value
- const pricemaxFIlter = document.getElementById("PriceMax").value
- console.log(" title =" + TitleFIlter);
- console.log("description = " + descriptionFilter);
- console.log(" PriceMin =" + priceminFIlter);
- console.log("PriceMax = " + pricemaxFIlter);
-
- const url = `api/upload/${TitleFIlter}/${descriptionFilter}/${priceminFIlter}/${pricemaxFIlter}`
- const response = await axios.get(url)
- const data = await response.data;
- this.setState({
- allproducts: data,
- tableLoading: false
- });
- console.log(data);
- }
this is my backend(asp net core API):
- HttpGet]
- [Route("{Title?}/{Description?}/{Pricemin?}/{Pricemax?}")]
- public async Task<List<Product>> GetFilter([FromQuery]
- string Title,
- string Description,
- int PriceMin,
- int PriceMax
- )
- {
- IQueryable<Product> products = _context.products;
-
-
- if (!string.IsNullOrEmpty(Title))
- products = products.Where(x => x.Title.ToLower().Contains(Title.ToLower()));
-
- if (!string.IsNullOrEmpty(Description))
- products = products.Where(x => x.Description.ToLower().Contains(Description.ToLower()));
-
- if (PriceMin > 0)
- products = products.Where(x => x.Price >= PriceMin);
-
- if (PriceMax > 0)
- products = products.Where(x => x.Price <= PriceMax);
-
- return await products.ToListAsync();
- }
Anytime I dont fill in all the filter inputs I get a 404 error
How do i solve this