设置为默认页/主页后直接访问操作

时间:2019-07-10 01:37:56

标签: c# asp.net asp.net-mvc razor routes

在我的RouteConfig.cs中:

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

localhost/可以访问它

如何通过其实际链接localhost/Search/Results访问它。

将其设为默认值后,实际的直接链接显示Resource cannot be found

enter image description here

1 个答案:

答案 0 :(得分:0)

RouteConfig.cs:

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

控制器:

          public class SearchController : Controller
           {
           public ActionResult Index()
            {
              return View("Results");
            }
         }

现在,它将工作。

                      OR

RouteConfig.cs:

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

控制器:

          public class SearchController : Controller
           {
           public ActionResult Results()
            {
              return View("");
            }
         }