为什么RedirectToAction重定向到<param />。com

时间:2013-05-08 17:40:05

标签: c# asp.net .net asp.net-mvc asp.net-mvc-4

我们有一个mvc4站点,其中HomeController.Index()具有以下代码

RedirectionToAction("Page", new { id = "Home" } );

其中action Page定义为

 public ActionResult Page(string id)
    .....

在调试时,它以localhost:xxxxx开头,但随后重定向到www.home.com

关于设置断点,它甚至没有点击方法Page(string id )

关于在哪里寻找的线索?

1 个答案:

答案 0 :(得分:0)

看起来您可能遇到了一些路由问题。 RouteConfig.cs文件位于MVC4项目的App_Start文件夹中。

另一件事,如果您的Page操作与HomeController不同,那么您需要代码如下:

public ActionResult Index()
{
   return RedirectToAction("OtherController", "Page", new { id = "Home" });
}



我用你的重定向创建了一个基本的MVC4项目,它对我有用。用户最终到达以下URL:[http:// localhost:47272 / Home / Page / Home]

这是我的HomeController.cs

public class HomeController : Controller
{
   //
   // GET: /Home/

   public ActionResult Index()
   {
      return RedirectToAction("Page", new { id = "Home" });
   }

   public ActionResult Page(string id)
   {
      return View();
   }
}



这是我的RouteConfig.cs

public class RouteConfig
{
   public static void RegisterRoutes(RouteCollection routes)
   {
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

      routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
      );
   }
}