c# - 重定向到另一个未在路由中注册的 Controller /操作

标签 c# asp.net-mvc asp.net-mvc-3

iam 有像下面这样的 Controller ,它没有在路由表中注册

public class InternalController : Controller
{
 /*this controller is not registered in routes table*/ 

      public ActionResult Foo()
      {
         return Content("Text from foo");
      }
}

我想从另一个在路由表中注册的 Controller 调用/重定向前一个 Controller 的操作,该 Controller 未在路由表中注册。

public class AjaxController : Controller
{
 /*this controller is registered in routes table*/  

      public ActionResult Foo()
      {

           /*FROM HERE HOW DO I RETURN CONTENTS OF  
            controller=InternalController, action = Foo
           */

            /*
              i tried below piece of code but that doesnt seem to work
            */

            return RedirectToAction("Foo", "InternalController ");
      } 
}

Defined Routes(只添加了一项)

    public void RegisterRoutes(RouteCollection routes)
    {
       routes.MapRoute("Ajax","ajax/{action}",new {
       controller="Ajax",
       action="Index"
       });
   }

最佳答案

如果您选择不注册路由...那么您的文件/ Controller 可能位于不会更改的特定位置。

在那种情况下,只需使用“Redirect”方法,而不是“RedirectToAction”。

例如:

return Redirect("~/Internal/Foo");

关于c# - 重定向到另一个未在路由中注册的 Controller /操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7264030/

相关文章:

c# - 检查两个字符串数组中是否有相同的元素?

c# - 使用 while 循环时显示多行结果而不是一行

c# - 如何从 HttpContext (asp.net) 获取 "Host:" header

c# - MVC3 在 ActionLink OnComplete 事件上触发多个函数?

c# - ASP.Net MVC Helper LabelExtension 未按预期显示

c# - 将以编程方式生成的 DataGridTextColumn 的 Visibility 属性绑定(bind)到复选框

c# - OnClientClick 阻止 OnClick 事件?

c# - 使用硬盘驱动器扩展巨大的阵列

asp.net-mvc - 使用 MVC5 应用程序的 Angular Cli 延迟加载

c# - 如何在 ASP.NET MVC 中将 XML 文件发送到客户端