redirect to actionResult method from an api

1.4k views Asked by At
[HttpPost]
    public void insertData(string productid)
    {
        //insert to db
        string uri = this.Url.Link("Default", new { controller = "AddProducts", action = "Index" });
        //Response.Redirect(Url.Action("", ""));
    }

after inserting to the database i want to redirect to an actionResult method.i have a void method, what do i return it as?

1

There are 1 answers

1
AudioBubble On

Is this an MVC controller or a web Api controller?

If MVC :

You must return an ActionResult instead of void.

Your code will look like this one.

    [HttpPost]
    public ActionResult AddProduct(string productid)
    {
        //Add product to db logic goes here

        return RedirectToAction("{Your parameters here}");
    }

It's your task to go deeper into details. Take a look at this one to know more about ActionResult - https://msdn.microsoft.com/en-us/library/system.web.mvc.actionresult%28v=vs.118%29.aspx

If it's a web api:

You only return Http response messages. http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/action-results