I can do this by using this code :
[HttpPost("SampleRoute1")]
public JsonResult Post([FromBody]SampleModel1 value)
{
.....Functionone.....
return Json("");
}
[HttpPost("SampleRoute2")]
public JsonResult Post([FromBody]SampleModel2 value)
{
.....Functiontwo.....
return Json("");
}
but i cant do this :
[HttpPost("SampleRoute1")]
public JsonResult Post([FromBody]SampleModel1 value)
{
.....Functionone.....
return Json("");
}
[HttpPost("SampleRoute2")]
public JsonResult Post([FromBody]SampleModel1 value)
{
.....Functiontwo.....
return Json("");
}
it gives error "Type 'Controller1' already defines a member called 'Post' with the same parameter types"
so is there any way that i can make two Post in one controller with same paramter but with different route?
like this :
Posting(SampleModel1) => "Controller1\SampleRoute1" => Doing Function1
Posting(SampleModel1) => "Controller1\SampleRoute2" => Doing Function2
Yes, you can do that. Problem is that you're trying to have two methods in a class that have same name & parameters and that's not possible. You should change name of your methods to something different.
Note that the action name & Post request type are already specified in the HttpPost attribute so you don't have to rely on the method name.
[HttpPost("SampleRoute1")]
public JsonResult Aaa([FromBody]SampleModel1 value)
{
.....Functionone.....
return Json("");
}
[HttpPost("SampleRoute2")]
public JsonResult Bbb([FromBody]SampleModel1 value)
{
.....Functiontwo.....
return Json("");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With