【问题标题】:Map route in MVC to match a dot in URL在 MVC 中映射路由以匹配 URL 中的点
【发布时间】:2014-07-09 13:53:10
【问题描述】:

有没有办法像这样定义路由

  routes.MapRoute(
                name: "Language",
                url: "{controller}/{action}.{culture}",
                defaults: new { controller = "Home", action = "Index", culture = UrlParameter.Optional }
            );

并且能够处理像http://www.domain.com/Test/Create.us-US这样的url?

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing


    【解决方案1】:

    是的,你可以这样做,但是为像http://www.domain.com/Test/Create这样的网址添加路由,末尾不带点

    routes.MapRoute(
                name: "Language",
                url: "{controller}/{action}",
                defaults: new { controller = "Home", action = "Index", culture = "us-US" }
            );
    

    【讨论】:

      【解决方案2】:

      不,您可以在没有点的情况下创建路线,但您使用特殊字符到根。当我们当时在controler声明方法时,可以在路由中定义Action名

      routes.MapRoute(
                      name: "Default",
                      url: "{controller}/{action}/{id}",
                      defaults: new { controller = "Home", action = "DashboardV1_bm", id = UrlParameter.Optional }
                  );
      
      [HttpPost, ActionName("DashboardV1_bm")]
              [ValidateAntiForgeryToken]
              public ActionResult DashboardV1(int id)
              {
                  Shift shift = db.Shifts.Find(id);
                  db.Shifts.Remove(shift);
                  db.SaveChanges();
      
                  this.AddToastMessage("Delete", "Record is successfully deleted !", ToastType.Success);
                  return RedirectToAction("Index");
              }
      

      更多信息,请访问我的博客: http://programmingcode.in/create-routemap-to-access-new-created-view-page-in-mvc-dot-net/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-26
        • 1970-01-01
        • 1970-01-01
        • 2011-11-11
        • 2010-09-05
        • 1970-01-01
        相关资源
        最近更新 更多