[英]Get route result in ASP.NET Core
I'm working on an ASP.NET Coe Web API project.我正在开发一个 ASP.NET Coe Web API 项目。
I have a post
method (route) and I need it to call another get
method:我有一个post
方法(路由),我需要它来调用另一个get
方法:
[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.我最终会Get
资源。
But what I want is to take the result of that Get
method and continue in my post method.但我想要的是获取该Get
方法的结果并继续我的 post 方法。
In Python its something like在 Python 中,它类似于
amount = requests.get("http://"+catalogIpAddress+":"+port+"/count/" + str(id))
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 方法 使用路由参数值、路由名称或两者将请求重定向到新 URL 这意味着您无法继续使用上一个 URL
HttpResponse.RedirectToRoute Method HttpResponse.RedirectToRoute 方法
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.