-1

I am working on a project which have scenario to redirect to httppost method from another controller which have a httpget method. Can you guys suggest me a good approach to achieve it?

Example is given below

ControllerA :

    [HttpPost]
    [Route("Student/InsertData", Name = "InsertData")]         
    [RequiredQueryStringKeys("SystemId", "IncidentDt")]
    public IHttpActionResult InsertData([FromBody] StudentDetailRequest request)
    {
       //Code

    }

Controller B:

    [HttpGet]
    [Route("Student/GetDetail")]         
    [RequiredQueryStringKeys("SystemId", "IncidentDt", "Cd")]
    public IHttpActionResult GetDetail()
    {
     ------- Need to call ControllerA POST method here
    }

NOTE: My requirement is to reroute Student/GetDetail to Student/InsertData. If User hit Student/GetDetail then it should redirect to Student/InsertData.

3
  • What have you tried thus far? Have you tried using an HttpClient and making a restful call? Have you tried abstracting the business logic from the InsertData implementation to a service class that can be called directly? Commented Feb 22, 2022 at 15:07
  • I have tried return Redirect(new Uri(...)) but it is throwing error for Get method can not call Post like this... Commented Feb 22, 2022 at 15:10
  • Your InsertData is using StudentDetailRequest as an input parameter. Pls post the class and a show how are you going to init it. Commented Feb 22, 2022 at 15:58

1 Answer 1

0

If you have problems like this one, then you need to think about refactoring that. For example, you can write some UseCases, and just from your methods call that UseCase scenario. Try to write whole logic out of the controllers, then you will be able to reuse that again, instead of logic inside of methods in controller just try to handle request and call that UseCase what you need.

With this logic, you will also have problems when you want to call that POST method because he required some model, and you don't have it when you first call your GET method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.