RedirectToAction在另一个项目中

时间:2015-02-03 15:20:15

标签: c# asp.net-mvc

我有2个MVC项目。其中一个是API,我希望从这个API中将数据传递到同一解决方案中的另一个项目。怎么可能?

我在控制器的头部添加了引用

public class ProspectController : Controller
{
    DataContext db = new DataContext();
    // GET: Prospect
    public ActionResult Index()
    {
        Database.SetInitializer(
            new MigrateDatabaseToLatestVersion<DataContext, Configuration>());
        // The Controller in the other project 
        TestController t = new TestController();

        //return to the Controller in the other project   
        RedirectToAction("Index", "Project2.TestController", new {id=4});
    }
}

1 个答案:

答案 0 :(得分:5)

简短的回答是,你无法做你想做的事。 RedirectToAction使用路由表创建URL,您无法处理两个不同的应用程序和两个不同的路由表。

可以做的是使用RedirectResult将用户完全发送到另一个网址,无论是在同一个应用程序中还是在不同的应用程序中。

return Redirect("http://OtherSite/Test/Index?id=4");