Try
RedirectToRoute
. That should work for your case. A quick example is given below:
routes.MapRoute("Project",
"Route/Directives/{projectId}/{machineName}/{companyId}",
new { controller = "Route", action = "Directives", projectId = @"\d+", machineName = @"\S+", companyId = @"\d+" });
Notice that I have hard-coded the controller & action, you could also use your method and pass the controller and action as route values.
Now in your controller, instead of RedirectToAction, use RedirectToRoute as shown in the Index action method.
public class RouteController : Controller
{
public ActionResult Index()
{
return RedirectToRoute("Project", new { projectId = 4, machineName = "somemachine", companyId = 7 });
}
public ActionResult Directives(int projectId, string machineName, int companyId)
{
ViewData["Data"] = string.Format("{0},{1},{2}", projectId, machineName, companyId);
return View();
}
}
Now, if you navigate to
/route/index
it will redirect you to
/Route/Directives/4/somemachine/7
instead of how you get currently.
Hope this helps!