views:

138

answers:

1

The rails convention is to use New and Create for RESTful action names. The .NET MVC convention appears to be to use Create for both (usually with a post restrictor on the action intended to the true 'Create' method).

Personally I would prefer to use New and Create in .net but have been using Create for both given the convention. What (if any) is the benefit of the .NET MVC convention of using Create for both actions?

The same goes for Edit and Update?

+4  A: 

One benefit is that you can write code like:

<% using (Html.BeginForm()) { %>

... instead of code like:

<% using (Html.BeginForm(new RouteValueDictionary{ "action", "Update" })) { %>

Similarly for error handling:

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

... instead of:

if (!ModelState.IsValid)
{
    return View("Edit", model);
}

MVC's convention is that related stuff is named the same, not that your actions must have certain names.

Craig Stuntz
This information is good. It's not just form but has functional value as well. (Though I've been doing return View("Edit", model) anyway as I believe that you cannot test the destination view name without explicitly declaring it ... I could be wrong).
Michael Gattuso
Sure you can test it. You just test it to equal string.Empty, which, in MVC, means "the same as the action name, whatever that is."
Craig Stuntz
Good point - sometimes I can to get too explicit!
Michael Gattuso