Congratulations - C# Corner Q4, 2022 MVPs Announced
Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
osyris zosar
1.9k
289
15.1k
querystring parameters are not working in API
Jun 2 2021 4:30 PM
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
Reply
Answers (
4
)
How to read JSON data in c# code.
how to add tooltip in connectors in Kendo diagram