【问题标题】:Route/redirect to default action by calling the controler in url?通过在 url 中调用控制器来路由/重定向到默认操作?
【发布时间】:2016-04-06 07:00:48
【问题描述】:

网址:localhost:4835/登录

public class LoginController : Controller
{
    public ActionResult Index()
    { 'enter code here' }
}

我想在不提及动作名称的情况下调用 index。

【问题讨论】:

  • 显示路线定义

标签: asp.net-mvc routedata


【解决方案1】:

您的RouteConfig 文件中应该有这样的内容:

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

您可以拥有自己的映射,这里只是提供了一个示例。

【讨论】:

    猜你喜欢
    • 2011-12-30
    • 2013-04-22
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 1970-01-01
    • 2013-06-12
    相关资源
    最近更新 更多