Reputation: 1699
With 2 routes as follows:
[HttpGet("rules")]
public async Task<IActionResult> GetRulesAsync(DateTime? businessDate = null, string
category = null)
{
//...
}
[HttpGet("effectiveRules")]
public async Task<IActionResult> GetEffectiveRulesAsync(DateTime? businessDate = null, string
category = null)
{
//want to redirect this to [HttpGet("rules")]
}
How can I redirect from second to the first API?
Tried RedirectToRoute
un-successfully.
Could anyone please help?
Upvotes: 1
Views: 1006
Reputation: 18209
Here is a working demo to use RedirectToAction
:
[Route("[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
[HttpGet("rules")]
public async Task<IActionResult> GetRulesAsync(DateTime? businessDate = null, string
category = null)
{
//...
}
[HttpGet("effectiveRules")]
public async Task<IActionResult> GetEffectiveRulesAsync(DateTime? businessDate = null, string
category = null)
{
return RedirectToAction("rules", new { businessDate = businessDate, category = category });
//want to redirect this to [HttpGet("rules")]
}
}
Upvotes: 1
Reputation: 1699
return Redirect($"rules?businessDate={businessDate:yyyy-MM-dd}&category={category}");
worked.
Upvotes: 0