I have a fairly simple single-page application that uses AJAX to load and replace contents of the page. The application should allow user to add phone numbers to a customer. After user loads a view to add a new phone number by clicking on Ajax.ActionLink on customers page he can submit an AJAX form with a number to be added, and if the value is a number he should be redirected back to the customers page. Here is where I stuck, how do I return a result of another action? It seems that I can't use RedirectToAction since it returns 302 and the browser initiates a GET request which is not allowed verb in my situation, the browser gets back 404 as a result.
So I have two controllers, PhoneBookController and CustomersController. User loads Customers/Details view and clicks on Ajax.ActionLink which calls PhoneBook/Add action, this action returns a view with an AJAX form which is being submitted to PhoneBook/Create action.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Phone ph, string Caller)
{
if (ModelState.IsValid)
{
ph.Active = true;
db.PhoneBook.Add(ph);
db.SaveChanges();
/*->*/ return RedirectToAction("Details", "Customers", new { Id = ph.CustomerId }); //what should be used instead?
}
return PartialView("Add", ph);
}
How this type of tasks usually are accomplished?