[英]Route Issue ASP.net MVC 4 not redirecting to Index Action
When I try to access to index Page on controller if I use this URL format : 当我尝试使用以下URL格式访问控制器上的索引页面时:
mydomain/taux/index
This works and the Index
page is opened. 这有效,并且Index
页面打开。 But if I use this url format (I don't add the Index
action to URL) 但是,如果我使用这种url格式(我不将Index
操作添加到URL)
mydomain/taux/
I got "404 not found", but normally it should works and redirect me to index page automatically. 我收到“ 404未找到”,但通常它应该可以正常工作,并自动将我重定向到索引页。
How to fix it please ? 请如何解决?
Taux
Controller : Taux
控制器:
// GET: /Taux/
public ActionResult Index()
{
var taux = db.TAUX.Include(t => t.CATEGORIE).Include(t => t.GARANTIE);
return View(taux.ToList());
}
RouteConfig.cs
: 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 = "Account", action = "Login", id = UrlParameter.Optional }
);
}
}
This is because your default action is set to Login. 这是因为您的默认操作设置为“登录”。 You need to set it to Index if you want link mydomain/taux/ to redirect to Indext action 如果要将链接mydomain / taux /重定向到Indext操作,则需要将其设置为Index。
If you want to have the redirect just for this specific controller you can use the following route definitions: 如果只想为此特定控制器进行重定向,则可以使用以下路由定义:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Taux",
url: "Taux/{action}/{id}",
defaults: new { controller = "Taux", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.