RedirectToAction not redirecting to Get Action of another controller

481 Views Asked by At

Hi I have two controllers with their action methods and views. First controller is:

[Authorize]
public class CarController : Controller
{
    private readonly ICarService carService;

    public EventController(ICarService carService)
    {
        this.carService= carService;
    }

    public IActionResult Create() 
        => View();

    [HttpPost]
    public async Task<IActionResult> Create(CarFormModel carFormModel)
    {
        if (!ModelState.IsValid)
        {
            return View(carFormModel);
        }

        var resultId = await this.eventService
            .CreateEventAsync(carFormModel);

        TempData["EventId"] = resultId;
        return RedirectToAction("Create","Manager");
    }

and my other controller:

[Authorize]
public class ManagerController : Controller
{
    private readonly IManagerService managerService;

    public ManagerController(IManagerService managerService) 
        => this.managerService= managerService;

    public IActionResult Create()
        => View();

    [HttpPost]
    public async Task<IActionResult> Create(ManagerCreateModel managerCreateModel)
    {
        var created = await this.managerService
            .CreateManagerAsync(managerCreateModel);
        if (!created)
        {
            return View(routeCreateModel);
        }
        return View("All");

    }

If I create car successfully Create action of Car controller is supposed to redirect me to create action of ManagerController(GET method/first one/) but instead of that it redirects me to the second one(POST method). Both controllers have their respective views in their folders. How to redirect to the get method of ManagerController?

1

There are 1 best solutions below

2
Serge On

change the action name

public IActionResult CreateView()
        => View();

and redirect

return RedirectToAction("CreateView","Manager");