I have an ASP.NET MVC app. My app is using T4MVC. In my controller, I need to redirect from one action to another. When I do this, I want to append a query string value. I can successfully redirect without the query string value, but I've been unsuccessful applying a query string value. My actions look like this:
[HttpPost]
[ValidateAntiForgeryToken]
public virtual ActionResult Action1()
{
return RedirectToAction(MVC.MyController.Action2().AddRouteValue("id", "5"));
}
[Route("action-2")]
public virtual ActionResult Action2(string input)
{
ViewBag.Input = input;
return View(viewModel);
}
The Action2 works fine when I visit ./action-2. I can also successfully POST to Action1. But, when the redirect doesn't work. I notice in the address bar the following:
/MyController/id
Why? How do I fix this? I just want to redirect back to Action2 but this time with a query string parameter added. What am I missing?
return RedirectToAction("Action2", "MyController", new { id = 5});?