c# - Routing POST with Query Parameters in MVC Web API -
in web apì project, use like:
post/mycontroller/1
but post/mycontroller/1?user=john
it easy because framework routes correctly each function. however, when use post, not work. have 2 post functions in same controller. example:
void post(int id, string content) and
void post(int id, string content, string user) i hope when call post/mycontroller/1?user=john, framework routes post(int id, string content, string user)
i know can use binding models, doing model class , 1 unique post function, mess because have many functions , able use query parameters route correct function. possible?
try declaring parameter [frombody] , [fromuri] attribute this:
public string post(int id, [frombody]string content, [fromuri] string user) { return "content = " + content + "user = " + user; } with above code able call
/test/1?user=ryan
request body
"test body"
and result is:
"content = test bodyuser = ryan"
hope helps.
Comments
Post a Comment