在AccountController
中,我为一个操作指定了四条路由:
[AllowAnonymous]
[HttpGet("/go", Order = 2)]
[HttpGet("/ex", Order = 2)]
[HttpGet("/men", Order = 2)]
[HttpGet("/ing", Order = 2)]
public async Task<IActionResult> Register()
{
return View();
}
例如,可以使用localhost:222/men
执行此操作
[AllowAnonymous]
[HttpPost]
public async Task<IActionResult> Register( RegisterViewModel model)
{
model.Code = Request.Path.Value;// HERE i want to get url path (/men,/ing ...)
var platformResponse = await _factory.RegisterAsync(model);
return View();
}
如何获得此路线值?Request.Path.Value
返回-〉“帐户/注册”
1条答案
按热度按时间s8vozzvw1#
您可以使用Request.query获取路由的当前值。
注意这里的route是routevalue的值。就像你的url中有:
localhost:8080/?routevalue=ing
,因此您应该获得路由值的值。来源:https://makolyte.com/aspnetcore-getting-query-string-values/