I upgraded a webapi solution from 2.1 to 3.1.
My Startup.cs file contains:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddMvc().AddNewtonsoftJson();
..
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
..
My controller starts with:
[ApiController]
[Route("api/[controller]/[action]")]
public class MyFooController : Controller
and here is my action:
[HttpPost]
public string MyFooAction(string value)
So I call action from another easy solution with:
var param = new NameValueCollection();
param["value"] = "3";
using (var client = new WebClient())
{
var data = client.UploadValues(url, "POST", param);
In debug, the call gets the action route but value=null always. I also tried with [FromBody] but it's the same.
I read in 3.1 would be prefer inherint controller from ControllerBase class but I have many action that return Json(obj) and that is not present in ControllerBase class but only in Contreller class: is this the problem?
Thanks in advance.