My controller contains
[Route("/sales")]
public IActionResult Index()
{
Model myModel = new Model();
return test(DateTime.Today, DateTime.Today, myModel);
}
and the test method
[HttpPost]
[ValidateAntiForgeryToken]
[Route("/sales/{startDate}/{endDate}/{myModel}")]
public IActionResult test(DateTime startDate, DateTime endDate, Model myModel = null)
{
myModel ??= new Model();
return View(myModel);
}
On page load everything works as expected. Index method, passes the model to the test function.
Unfortunatelly when an AJAX post occures at
/sales/2020-05-14/2020-05-14/null
i get an internal server error (500), which seems to be logical.
But how can i fix that? Is there any attribute that i can decorate the optional parameter Model myModel = null
Actually i want to treat this property as dummy when called from client side, and that is why i have set it to null.