ASP.NET MVC Routing two GUIDs

前端 未结 2 1617
半阙折子戏
半阙折子戏 2021-02-10 06:49

I have an action taking two GUIDs:

public class MyActionController : Controller
{
  //...

  public ActionResult MoveToTab(Guid param1, Guid param2)
  {
    //..         


        
相关标签:
2条回答
  • 2021-02-10 07:17

    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 }
    );
    
    0 讨论(0)
  • 2021-02-10 07:32

    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);
      }
    
    0 讨论(0)
提交回复
热议问题