开发者

What are typical ASP.NET MVC - Controller Action Name conventions?

I'm struggling to choose appropriate names for my actions. I want to distinguish between actions that return a view to:

  1. Create
  2. Edit
  3. Edit-Create

Here is what I have so far:

Create --> Show the Empty Form for Create  
Add    --> Receives data from Create and Save New Entity  
Edit   --> Shows Existing Entity in a form for editing  
Update --> Saves the ch开发者_运维问答anges on an existing Entity  
???    --> Shows the form for either editing or creating depending on the 
           situation  
Save   --> Either saves or updates the entity depending on whether the entity 
           already exists or not.  

So, What would be an appropriate name for the action that Shows the Create/Edit view, which sends its data to Save.

I had considered CreateEdit since it's clear and specific, but I'm not sure. Any suggestions?


I typically use Create() for adding a new entity and Edit() for editing one.

I overload the GET & POST methods and add an [HttpPost] attribute to the one that receives the data, e.g.:

public ActionResult Create()
{
    // this one renders the input form
    ...
    return View();
}

[HttpPost]
public ActionResult Create( MyViewModel model )
{
    // this one accepts the form post
    if ( ModelState.IsValid )
    {
       ...
       return RedirectToAction( ... );
    }
    return View( model );
}

This convention makes it easy to find related methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜