Home > Blockchain >  Get route result in ASP.NET Core
Get route result in ASP.NET Core

Time:06-11

I'm working on an ASP.NET Coe Web API project.

I have a post method (route) and I need it to call another get method:

[HttpGet(Name = "Profile")]
public async Task<ActionResult<ProfileResponseDto>> GetProfile(string username)

If I call :

return RedirectToRoute("Profile", new { username = profile.UserName });

I will end up with Get resource.

But what I want is to take the result of that Get method and continue in my post method.

In Python its something like

amount = requests.get("http://" catalogIpAddress ":" port "/count/"   str(id))

CodePudding user response:

HttpResponse.RedirectToRoute Method Redirects a request to a new URL by using route parameter values, a route name, or both this means that you cannot continue with the last URL

HttpResponse.RedirectToRoute Method

but you can return value from another action result like

var result = await controller.GetTodosAsync();

so you can use like this :

        [HttpGet(Name = "Profile")]
        public async Task<string> GetProfile(string username)
        {
           return await Task.Run(()=> "hello") ;
        }

        [HttpPost(Name = "Profile")]
        public async Task<string> PostProfile(string username)
        {
            string result = await this.GetProfile(username);

            result = result   " from post";
            return await Task.Run(() => result);
        }
  • Related