.NET MVC URL 路由帮助
我正在尝试在 .NET MVC 应用程序中配置 ErrorController,但当前无法在控制器上执行任何操作,因此我相信这可能是因为我需要在 global.asax< 中注册 URL 路由/b>
错误控制器如下:
public class ErrorController: Controller
{
/*Default Redirect Error Page*/
public ActionResult Index()
{
return View();
}
/*Generic Error Page*/
public ActionResult Generic()
{
return View();
}
/*Status Code: 400*/
public ActionResult NotFound()
{
return View();
}
}
我希望能够分别通过以下 URL 调用上述操作。
〜/错误/
〜/错误/通用
~/Error/NotFound
我相信在 Global.asax 文件中,我需要使用如下所示的内容来注册这些路由:
routes.Add(new Route("error/{action}", new MvcRouteHandler())){controller = "Error", action = "";
How will I add/specify the Correct Route handler for this ?
I am trying to configure an ErrorController in my .NET MVC application, and I am unable to hit any actions on the controller currently, so I believe it may be because I need to register the URL route in the global.asax
The Error controller is the following:
public class ErrorController: Controller
{
/*Default Redirect Error Page*/
public ActionResult Index()
{
return View();
}
/*Generic Error Page*/
public ActionResult Generic()
{
return View();
}
/*Status Code: 400*/
public ActionResult NotFound()
{
return View();
}
}
I would like to be able to call the actions above by the following URL's respectively.
~/Error/
~/Error/Generic
~/Error/NotFound
I would believe that in the Global.asax file I would need to register these routes using something like the following:
routes.Add(new Route("error/{action}", new MvcRouteHandler())){controller = "Error", action = "";
How would I add/specify the correct route handler for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信 global.asax 中提供的默认 url 适用于您的 url,但如果您想要特定的 url,请选择:
如果您想要参数:
I believe that the default url provided in global.asax would work for your url but if you want a specific url then go for:
and if you want parameters: