代码之家  ›  专栏  ›  技术社区  ›  Alon Gubkin

超载ASP.NETMVC操作

  •  5
  • Alon Gubkin  · 技术社区  · 14 年前

    我怎样才能让动作过载ASP.NETMVC,但是支持GetQueryString?我试着这样做:

    public JsonResult Find(string q)
    {
        ...
    }
    
    public JsonResult Find(string q, bool isBlaBla)
    {
        ...
    }
    

    但每当我进入 /controller/find?q=abc /controller/find?q=abc&isBlaBla=false System.Reflection.AmbiguousMatchException .

    如何解决这个问题?

    3 回复  |  直到 14 年前
        1
  •  2
  •   willbt    14 年前

    public JsonResult Find(string q, bool isBlaBla)
    {
    
    }
    

    你甚至可以利用 Optional Parameters and Name Arguments 如果你用的是C#4.0

        2
  •  1
  •   Darin Dimitrov    14 年前

        3
  •  0
  •   Paul Creasey    14 年前

    你应该使用路线,例如。 find/abc find/abc/false

    HttpContext