There is a mistake in the video: [HttpGet("{search}")] should've been [HttpGet("search")]. Because we want the word "search" as a literal segment in the URL path, surrounding it by curly braces makes it a route parameter, that is not semantically correct even though it would still work (if you've set the ":int" constraint for the "id" in the other action methods in this controller that take an ID, if you haven't, it would throw an "AmbiguousMatchException"). It would work because it would consider the word "search" in the URL as a value for the "search" route parameter, so that means that basically, any other word in that segment would still match the "Search" action method.
It actually doesn't work with curly braces like {search}. I got an error in postman saying 'request matched multiple endpoints' when using the curly braces. It matched also with with the normal Get() Endpoint AND with the search Endpoint Switching to HttpGet("search") fixed my problem tho
Great job on the tutorials, VERY HELPFUL... Just in case anyone else is going through this and having a problem with getting the Search(string name, Gender? gender) working... Not sure if changed from the Blazor preview... But running with the latest (i'm running with .Net Core 3.1) in case you are not getting any results because your query parameters are coming in null.... Not sure if this is the best way but this is how it got it working that differs from the video... In the external facing Search method, Search should be (Note the [FromQuery]) with out the FromQuery no matter what was getting null for both params.: public async Task Search([FromQuery] string name, Gender ? gender) HTH.
Thank You So MUCH for your time & effort to explain !!! BTW, I am using SQLite for my setup and the search's name=john behaves as it is case sensitive. So I just slightly modified the search to be FirstName.ToLower().Contains(name.ToLower()) and LastName.ToLower().Contains(name.ToLower()
Hello Bhuwan - Thank you very much for the feedback. Means a lot. I have included all the Blazor tutorial videos, slides and text articles in sequence on the following page. Hope you will find it handy. www.pragimtech.com/courses/blazor-tutorial-for-beginners/ When you have some time, can you please leave your rating and valuable feedback on the REVIEWS tab. It really helps us. Thank you. Good luck and all the very best with everything you are doing.
3:00 On line# 59 of EmployeeRepository.cs, if your data table has a million records, does this code get all of them and then applies a filter to it afterwards?
Hi, the "{search}" in the route template should not be in curly brackets .. because it's not a route parameter am I wrong? thanks for the great tutorials by the way...
Sir, need one clarification, so, for any Get methods with paramaters, if we hit the method with ?name=value, by default it will take that as query parameter and execute it right?
Hello @kudvenkat Why for GetEmployees() we have only public async Task and for Search() we need public async Task ? File EmployeesController.cs I can not understand the diference. In both results I should get some list of employees. Thank you for comment in advance.
Hope you can demonstrate adding records using one to many relationship like an Order Header and Order Details table, on the order details table, it has a lookup on the Items table to search for items ordered by customers, same with the Order Header where the end user will search for the customer. Order details total is displayed and saved on the Order Header. Thanks!
What is the advantage of calling "return await query.ToListAsync();" instead of "return query.ToList();"? The second option seems to be more eficient ans simpler, isn´t it?
Sir, Can you add a PhotoPath column in Employee model? So that we can learn about "How to upload image using Web API". Once we know how to upload image Web API We can apply same logic in different kind of frameworks like Angular, React... Best regards, Thank you sir. Md Towhid.
Hello, I got some error. I really appreciate the help from you. Thank you sir! Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches: EmployeeManagement.Api.Controllers.EmployeesController.GetEmployee (EmployeeManagement.Api) EmployeeManagement.Api.Controllers.EmployeesController.Search (EmployeeManagement.Api) at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(CandidateState[] candidateState) at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, CandidateState[] candidateState) at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.Select(HttpContext httpContext, CandidateState[] candidateState) at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext) at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher.MatchAsync(HttpContext httpContext) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) Controller Code: [HttpGet("{search}")] public async Task Search(string name, Gender? gender) //extension [HttpGet("{id:int}")] public async Task GetEmployee(int id)
Sir, For me [HttpGet("{search}")] triggers Multiple matches to Search() and Get() Actions. Tried lot of combinnations of attributes HttpGet and Route but only [HttpGet("/[action]")] /works. And it maps to baseUrl/actionMethod. My Application: dotnet new blazorwasm -hosted -output MyApplication -pwa .netcore 5.0 8th review Please advise. Regards.
There is a mistake in the video: [HttpGet("{search}")] should've been [HttpGet("search")]. Because we want the word "search" as a literal segment in the URL path, surrounding it by curly braces makes it a route parameter, that is not semantically correct even though it would still work (if you've set the ":int" constraint for the "id" in the other action methods in this controller that take an ID, if you haven't, it would throw an "AmbiguousMatchException").
It would work because it would consider the word "search" in the URL as a value for the "search" route parameter, so that means that basically, any other word in that segment would still match the "Search" action method.
It actually doesn't work with curly braces like {search}. I got an error in postman saying 'request matched multiple endpoints' when using the curly braces. It matched also with with the normal Get() Endpoint AND with the search Endpoint
Switching to HttpGet("search") fixed my problem tho
You can do this too:
[HttpPost]
[Route("catalog-items")]
Really appreciate the effort you're putting in! You're the best by a mile!
Great job on the tutorials, VERY HELPFUL...
Just in case anyone else is going through this and having a problem with getting the Search(string name, Gender? gender) working... Not sure if changed from the Blazor preview... But running with the latest (i'm running with .Net Core 3.1) in case you are not getting any results because your query parameters are coming in null.... Not sure if this is the best way but this is how it got it working that differs from the video...
In the external facing Search method, Search should be (Note the [FromQuery]) with out the FromQuery no matter what was getting null for both params.:
public async Task Search([FromQuery] string name, Gender ? gender)
HTH.
Thank You So MUCH for your time & effort to explain !!! BTW, I am using SQLite for my setup and the search's name=john behaves as it is case sensitive. So I just slightly modified the search to be FirstName.ToLower().Contains(name.ToLower()) and LastName.ToLower().Contains(name.ToLower()
Great Videos as always keep it up Venkat
Completed all tutorials and successfully coded along with confidence, my worthy Easter break :) Thank you Venkat
Hello Bhuwan - Thank you very much for the feedback. Means a lot. I have included all the Blazor tutorial videos, slides and text articles in sequence on the following page. Hope you will find it handy.
www.pragimtech.com/courses/blazor-tutorial-for-beginners/
When you have some time, can you please leave your rating and valuable feedback on the REVIEWS tab. It really helps us. Thank you. Good luck and all the very best with everything you are doing.
Excellent. Thanks a lot.
Thank you God bless you
3:00 On line# 59 of EmployeeRepository.cs, if your data table has a million records, does this code get all of them and then applies a filter to it afterwards?
Thanks Venkat! 👍
Thanks a lot Venkat
Hi, the "{search}" in the route template should not be in curly brackets .. because it's not a route parameter am I wrong?
thanks for the great tutorials by the way...
Sir, need one clarification, so, for any Get methods with paramaters, if we hit the method with ?name=value, by default it will take that as query parameter and execute it right?
Hi @kudvenkat, thank you. Your tutorials help me so much.
Can you please tell me when you will be making tutorials on WPF?
WPF is painful to learn.
Hello @kudvenkat
Why for GetEmployees() we have only public async Task
and for Search() we need public async Task ?
File EmployeesController.cs
I can not understand the diference. In both results I should get some list of employees.
Thank you for comment in advance.
Hope you can demonstrate adding records using one to many relationship like an Order Header and Order Details table, on the order details table, it has a lookup on the Items table to search for items ordered by customers, same with the Order Header where the end user will search for the customer. Order details total is displayed and saved on the Order Header. Thanks!
thanks for you
Thank you !
Hello @kudvenkat, I want create search method in web api from many fields for saech. Please help me
What is the advantage of calling "return await query.ToListAsync();" instead of "return query.ToList();"?
The second option seems to be more eficient ans simpler, isn´t it?
Hi, How to order by that await call.?
Sir,
Can you add a PhotoPath column in Employee model?
So that we can learn about "How to upload image using Web API".
Once we know how to upload image Web API We can apply same logic in different kind of frameworks like Angular, React...
Best regards,
Thank you sir.
Md Towhid.
Hello, I got some error. I really appreciate the help from you. Thank you sir!
Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches:
EmployeeManagement.Api.Controllers.EmployeesController.GetEmployee (EmployeeManagement.Api)
EmployeeManagement.Api.Controllers.EmployeesController.Search (EmployeeManagement.Api)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(CandidateState[] candidateState)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, CandidateState[] candidateState)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.Select(HttpContext httpContext, CandidateState[] candidateState)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher.MatchAsync(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Controller Code:
[HttpGet("{search}")]
public async Task Search(string name, Gender? gender) //extension
[HttpGet("{id:int}")]
public async Task GetEmployee(int id)
Why do we use curly brackets here?
_HttpGet("{search}")_
Can't we just use without them?
_HttpGet("search")_
so that you can pass a parameter after '/search'
like this '.../search?name=john'
Can You please explain implement authentication to call asp net core webapi before call api into blazor
Sir,
For me [HttpGet("{search}")] triggers Multiple matches to Search() and Get() Actions.
Tried lot of combinnations of attributes HttpGet and Route but only [HttpGet("/[action]")] /works.
And it maps to baseUrl/actionMethod.
My Application:
dotnet new blazorwasm -hosted -output MyApplication -pwa
.netcore 5.0 8th review
Please advise.
Regards.
I keep getting "the name field is required" when I search by gender
In the controller I had to put "public async Task Search(string?name, Gender? gender)"
Selftaught programmers jesus!
I'm glad that you realize there are only two genders; male and female! LOL