With MVC controllers and two methods sharing the same name - they have to differ by HTTP verb (get / post). If the action method is not decorated by [HttpGet] or [HttpPost] it is considered both. Are these two being decorated by different verb ?
On 14 July 2014 16:15, Stephen Price <[email protected]> wrote: > Hey all, > > Just hit an error in my mvc controller after I added a new method to it. > It was complaining that I wasn't providing a value for a second property. I > was a bit confused for a second until I realised that it was calling my > newly added method when my intent was that it should still be calling the > original method. > > That probably doesn't make sense. Original method being called as httppost > was working fine. New method with different signature (two parameters) is > now being called instead. I realise now what's going on, that methods on > your controllers are called based on their signature (name doesn't matter). > It's a bit to get my head around when compared with WCF or web services > where you can call a named method in a class and you can have as many as > you like as the name is part of the signature. It would seem that MVC > controllers (and WebApi) you can only have one of each type of call. > Or do I need to add extra routes to be able to have additional methods on > my controller? (ie a method with three parameters) > > So my question is, what to do to group like functionality together when > you have to split everything up into its own controller? I guess the > controller could be treated as a facade into a class (with each class > having whatever methods you like on it). Is that the normal way to go? With > lots of different calls I imagine you'd end up with dozens of controllers. > Also what do you do when you have more than one call from a view? It seems > a view matches up with a controller so if you have one view with say 5 > different calls on it (ajax calls for example), you'd need a different > controller for each one as you can't put them into a single controller. > > I'm sure there's a good explanation of this somewhere in an MVC book > somewhere but i'm not even sure what you call this structure. > > Sorry if my question is a bit vague. :) > cheers, > Stephen >
