I'd like to know how to specify routes in dot net core. For example, I have a get method, which gets 1 argument(id), and returns user. This method is available through this link (api/user/1). So, the question is how to make a method to this link -"api/user/1/profile" so that it will get ID and returns something relevant to this ID. Is it necessary to make 2 get methods, or just separate them and specify routes?
ASP dot net core
178 Views Asked by Bekzat Shayakhmetov At
2
There are 2 best solutions below
0
ChrisDunne
On
If you haven't changed the default route from:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
You could create a User controller with something like:
public async Task<IActionResult> Profile(int? id)
{
if (id == null)
{
// Get the id
}
var profile = await _context.Profile
.SingleOrDefaultAsync(m => m.Id == id);
if (profile == null)
{
return NotFound();
}
return View(profile);
}
Then it would be mapped to "/User/Profile/{id}"
Obviously you can get the data for the profile however you wish, I just used an EFCore example.
Related Questions in ASP.NET
- Create an IIS web request activity light
- Writing/Overwriting to specific XML file from ASP.NET code behind
- What is the point of definnig Asp.net Intrinsic Objects In different places and what is the different betwen them?
- Deleting Orphans with Fluent NHibernate
- IOrderedEnumerable to vb.net IOrderedEnumerable Conversion
- Entity Framework Code First with Fluent API Concurrency `DbUpdateConcurrencyException` Not Raising
- Getting deeply embedded XML element values
- What is best way to check if any of the property of object is null or empty?
- NuGet - Given a type name or a DLL, how can I find the NuGet package?
- ASP-MVC Code-first migrations checkbox not active
- How do i add onclient click to my jquery button
- Jquery: Change contents of <select> tag dynamically
- Retrieving data from Oracle database
- ASP.NET: Fill Textbox field upon dropdownlist selection by user
- Why web API return 404 when deploy to IIS
Related Questions in ROUTES
- Routing Url that has no action name
- Implementing find node on torrent kademlia routing table
- Get packet that's being routed
- Preserve `$location.search()` in angular `redirectTo`?
- Why does this MVC action return a 404 response in IE11
- Backbone: Best way to prevent routes (and url change)
- ASP.NET MVC routing 404
- Change the name of parent :parent_id parameter in Routing resources for Rails4
- Where should I put Symfony third-party bundle's routing configuration?
- How to route by call method in proxy with WSO2?
- Asp.net MVC Routelink null controller parameter
- using dart route package url got error 404
- Re-transmission concept in TCP
- Network unreachable when address is IPv6 in Buildroot
- rails_admin add custom controller in namespace admin
Related Questions in ASP.NET-CORE
- ASP.NET 5 Class Library - Nuget package Web.Config transform
- Asp.Net 5 correct way to access logging config file from Startup.cs
- What is the difference between 'dependencies' and 'frameworkAssemblies' in project.json?
- Getting absolute URLs using ASP.NET Core
- How to add Project Reference in asp.net 5 application
- Configure the authorization server endpoint
- Observer for fire&forget Task
- IApplicationBuilder exists in both Microsoft.AspNet.Http.Abstractions and Microsoft.AspNet.Http
- What frameworks are available in ASP.NET Core (ASP.NET 5) applications?
- How do I include 'System.Runtime.Serialization.Json' namespace in my VSCode project on Mac OS X?
- How to suppress warnings when building an ASP.NET 5 project?
- Dependency Injection in asp.net 5 custom classes, what is the correct way?
- How to access IConfiguration property from Controller in ASP.NET 5
- Getting a scoped component from a IDocumentStoreListener
- How is execution passed from the clr to Startup class (startup.cs)?
Related Questions in ASP.NET-CORE-WEBAPI
- Determine port in asp.net core
- How to POST 2 or more objects to ASP.NET Core WebAPI
- Json problems using Angular2 and Net Core Web Api
- return html file from .Net Core api
- Using Dependency Injection with .NET Core Class Library (.NET Standard)
- Using Cookies based authentication in WebAPI and asp.net core
- Unit testing controller methods which return IActionResult
- ASP .NET MVC Core WEB API upload file showing error using Angular JS
- Sending requests from spa to .netcore web api using adaljs always returns 401
- Googe Authentication from .net Core not hitting my CallBackPtah that i have set in Startup Class
- Json response does not contain all the navigation properties EntityFramework Core and ASP .NETCore Web API
- Update model with TryUpdateModel in ASP.NET MVC Core Web API and Entity Framework Core doesn't work
- What is the correct DefaultScopedLifestyle for an asp.net Core Web API service using Simple Injector?
- How to send email with attachment using MimeMessage in asp.net core web API?
- How best to communicate between two ASP.NET Core server apps?
Related Questions in GET-METHOD
- Having problem with Try-Catch block in a Java I/O program
- How to get parameters from the URL with JSP
- How to login with retrofit2 using GET method
- Remove get method from url
- How to use GetMethod for static extension method
- Print http request response in JSON format
- How to show encrypted password in URL
- Keeping GET variables from 1 page to anonter
- How can I get $_GET values to a variable
- how to append int value to GET url of retrofit in android
- Ajax response printing whole php code written in php file, What to do?
- how to Change a GET method URL to clean URL in php?
- GET method in php clean URL
- comet callback-polling and jetty-cometd implementation
- How to pass Arabic string via url (GET method) properly to find substring using php?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Using attribute based routing, it can be done like this.
More information on routing can be found at this link.
https://docs.asp.net/en/latest/fundamentals/routing.html