json - GET and parameterless GET causing AmbiguousActionException? -


i'm trying have 2 web api methods in controller. 1 when called myviewmodel object in header, , 1 without.

mycontroller.cs:

[produces("application/json")] [route("api/[controller]")] public class mycontroller : controller {     [httpget]     public ienumerable<usermodel> get()     {         // ...     }      [httpget]     public ienumerable<usermodel> get(myviewmodel viewmodel)     {         // ...     } } 

but browsing route address in chrome without passing myviewmodel gives me error:

ambiguousactionexception: multiple actions matched. following actions matched route data , had constraints satisfied:

mycontroller.get (myproject)

mycontroller.get (myproject)

if comment out parameterless method , put break point in parameterized function , browse api url, looks rather viewmodel being null expected, appears new myviewmodel object made parameterless constructor. seems may relevant problem.

i'm running on microsoft.aspnetcore v1.1.2 , microsoft.aspnetcore.mvc v1.1.3.

add attribute routing 1 of them. example:

    [httpget("/myaction")]        public ienumerable<usermodel> get(myviewmodel viewmodel)    {     // ...    } 

or add of them. mvc can't distinguish 2 methods because viewmodel can null, , doesn't know if should match first action or another.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -