0

I am using ASP.NET MVC 4 and I have the home controller with a view and I created an API Controller, what I am trying to do is at the end of my method in my API Controller, to return the user to home controller view. How would I do this?

HomeController

namespace ASPNETMVC4_Tutorial.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }
}

My Api Controller

namespace ASPNETMVC4_Tutorial.Controllers
{
    public class PersonController : ApiController
    {
        [HttpPost]
        public dynamic Post([FromBody]PersonsClass person)
        {
            person.insertPerson(person);
            return true;
        }
    }
}

Please Help.

1 Answer 1

3

The api controller is not on charge of handling navigation, it should be client technology agnostic. This means, if the api is well designed and implemented, that you could use it on a mobile application, a web application or any other application type that can use the http protocol.

Url navigation is web specific and that's why can't be there. The correct place to do it on your case would be on succeed handler on javascript side.

1
  • I'd also mention that if you need more view logic that MVC can act as a proxy for requests to the API and wrap the results with additional view logic. Aug 28, 2014 at 19:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.