In ASP.NET MVC Should A Form Post To Itself Or Another Action?
- by Sohnee
Which of these two scenario's is best practice in ASP.NET MVC?
1 Post to self
In the view you use
using (Html.BeginForm) {
...
}
And in the controller you have
[HttpGet]
public ActionResult Edit(int id)
[HttpPost]
public ActionResult Edit(EditModel model)
2 Post from Edit to Save
In the view you use
using (Html.BeginForm("Save", "ControllerName")) {
And in the controller you have
[HttpGet]
public ActionResult Edit(int id)
[HttpPost]
public ActionResult Save(EditModel model)
Summary
I can see the benefits of each of these, the former gives you a more restful style, with the same address being used in conjunction with the correct HTTP verb (GET, POST, PUT, DELETE and so on). The latter has a URL schema that makes each address very specific.
Which is the correct way to do this?