views:

54

answers:

4

i see the convention is to have the post action be the same name as the page but to put a:

[AcceptsVerb.HTTPVerbs.Post]

on the action method.

Is there anything wrong with have the post action be another name.

So if i have a page called Edit, the Edit action will display that page, while the "Update"action will post the edit changes. This seems clearer to me as compared to having the Edit "Get" and the Edit "Post"

wanted to get peoples thoughts on this if this is purely a convention thing or is there a right and wrong here?

+1  A: 

I believe it's purely convention and there is nothing wrong with having different post action names.

The MVC default is to return a view with the same name as the action and the assumption is that you will want to return the same view whether you're getting or posting.
Also, changing the action name generally changes the URL, but if you don't care about that then go nuts with your action names.
I've used combinations of action names/purposes, depending on what seemed to make sense at the time.

AUSteve
A: 

In my opinion it doesn't matter how you name your actions, but it should be consistent within your site/application. I think, if you use REST as an API for your application, one would like to have actions like /system/accounts/user/34/addNote/ rather than updating the whole user or having another controller for notes.

Claus Trojahn
REST would be a POST to `/system/accounts/user/34/notes` instead of defining your own verbs in the URL.
Martijn Laarman
Jepp, you are right, `addNote` is a bad name in my comment above. But i'm still undertermined if it shouldn't be named `/system/accounts/user/34/notes/[index]|create|edit` after REST convention, which then would be a sub controller `Notes` for the `User` controller?
Claus Trojahn
A: 

Unless you're creating a RESTfull application, it doesn't really matter as long as your naming convention is consistent throughout your application.

Stephen Walther has a good article on naming conventions for naming your basic CRUD actions.

David G
+1  A: 

Using different names requires that you write more code.

If your GET and POST actions have the same name, then you can write views with code like:

<% Html.BeginForm() %>

...instead of...

<% Html.BeginForm("PostActionName") %>

Similarly, your post action could look like:

{
    if (!ModelState.IsValid) 
    {
        return View(Model);
    }
    // ...

... instead of:

{
    if (!ModelState.IsValid) 
    {
        return View("GetActionName", Model);
    }
    // ...

As you can see, there is not an overwhelming advantage of giving the actions the same name; it is simply a matter of convenience. The assumption that GET and POST actions will have the same name pops up in many different places in the framework. You can always override it, but that's what it is: Overriding an assumption.

Craig Stuntz