在我的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
答案 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("");
}
}