0

... which may not really be the question at all, but that's what it looks like to me right now.

I have a controller structure that has several layers of inheritance. The base controller is the one that implements Controller and has a method called Create(Guid var1, DateTime? var2) and is called like /MyDomain/Create/00000-0000-0000-000000.

I'm currently trying to implement a method in a controller lower down in the inheritance tree with the signature Create() which takes a QueryString parameter. (/MyDomain/Create?otherVar=somevalue) However, ASP.NET decides this is not valid as an "endpoint" and throws an error message saying The parameters dictionary contains a null entry for parameter 'var1' of non-nullable type 'System.Guid' for method 'System.Web.Mvc.ActionResult Create(System.Guid, System.Nullable`1[System.DateTime])'

I don't really know what is going on here. If I try to call another method on the same controller (with a name that is unique and not used higher up in the inheritance stack e.g. /MyDomain/DifferentMethod) it works without a problem.

My google-fu is coming up short on this problem.

Christian Wattengård
  • 5,543
  • 5
  • 30
  • 43
  • I know, I was going to mention that but it's a huge system and everything is proprietary and health-related. And I think the size and complexity is part of the problem, so I'm in a bit of a catch 22 in that regard. – Christian Wattengård Feb 11 '19 at 10:13
  • thats because the method in base controller always takes higher precedence over child controller so if you try to supply query string then first of all your base controller method hs been checked for overload. if those overload not satify then it thorws ans exception. – er-sho Feb 11 '19 at 10:18
  • Have you tried to use [Route] and [RoutePrefix] attributes on the controllers which inherit from the base one? The idea is to create different routes They might give you a fighting chance. We do need to see some code though, a cut down base controller and an implementing one. – Andrei Dragotoniu Feb 11 '19 at 10:47

1 Answers1

0

So you have something like:

public abstract class BaseController{

 [HttpGet]
 public IActionResult Create(Guid var1, DateTime var2){..
}

and

public class SomeClassController : BaseController{
 [HttpGet]
 public IActionResult Create(){..
}

The problem is that you cannot have 2 routes with the same name and different signature. This is because the routing don't know exactly where you want to go: with the url '/blalbalba/Create/' witch one you want? The base class or the inherited once? It's not so obvious.

Ps take a look on this answer:

ASP.NET MVC ambiguous action methods

IGionny
  • 135
  • 1
  • 1
  • 8