Michael Gattuso
Michael Gattuso

Reputation: 13200

'New' and 'Create' RESTful action names or 'Create' for both in ASP.MVC

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?

Upvotes: 3

Views: 335

Answers (1)

Craig Stuntz
Craig Stuntz

Reputation: 126547

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.

Upvotes: 5

Related Questions