ASP.NET MVC Routing two GUIDs

倾然丶 夕夏残阳落幕 提交于 2019-12-03 08:17:40

Yes, it is possible to map your parameters to System.Guid

routes.MapRoute(
    "MoveToTab",
    "{controller}/{action}/{param1}/{param2}",
    new { controller = "MyAction", action = "MoveToTab",
        param1 = System.Guid.Empty, param2 = System.Guid.Empty }
);

or

routes.MapRoute(
    "MoveToTab2",
    "myaction/movetotab/{param1}/{param2}",
    new { controller = "MyAction", action = "MoveToTab",
        param1 = System.Guid.Empty, param2 = System.Guid.Empty }
);

You can take in your two GUIDs as strings, and convert them to actual GUID objects using the GUID constructor that accepts a string value. Use the route that eu-ge-ne provided.

routes.MapRoute(
    "MoveToTab",
    "myaction/movetotab/{param1}/{param2}",
    new { controller = "MyAction", action = "MoveToTab", param1 = "", param2 = "" }
);

  public ActionResult MoveToTab(string param1, string param2)
  {
    Guid guid1 = new Guid(param1);
    Guid guid2 = new Guid(param2);
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!