2

So I'm working on my first true MVC website development (before now I've been using a template which was already developed). There we had a controller for controls (forms etc.) and then another controller just to deal with all HttpPost actions etc. Because of this is meant I could have a partial view called _ContactForm in both controller, one would set up the form view, the other would deal with the post back from the form.

I'm just wondering if there are any standard naming conventions now that I am using one controller. I have a partial view called _ContactForm which setups the view but Visual Studio informs me that I can't have a second _ContactForm to deal with the HttpPost even though I prefix the method with [HttpPost].

Is it best to have one method prefixed with an underscore and the other not, or is there some naming convention that is generally used?

Any help would be much appreciated!

Thanks, Mike.

Mike Upjohn
  • 1,251
  • 2
  • 16
  • 38
  • Please have a look at my answer on [Action Naming Convention](http://stackoverflow.com/questions/118474/action-naming-convention/38994001#38994001). Hope this helps... – Murat Yıldız Aug 17 '16 at 10:26

1 Answers1

3

I realize this question is old, but since there's no answer yet...

You can't have 2 methods of the same name with the same exact signature in a controller, even if one is decorated with the HttpPost attribute. Often times, the GET method either takes no parameter, or if it does a string or something, while the POST often takes a model, or JSON array, or something more substantial.

The point is, you need to make sure that the method signatures are different somehow, even if one is for the GET and one is for the POST.

Here is another post with a very similar, if not identical question:

post and get with same method signature

Good luck, and happy MVC coding!

Community
  • 1
  • 1
quantum kev
  • 108
  • 1
  • 9