tags:

views:

278

answers:

3

Using MVC out of the box I found the generated URLs can be misleading and I wanted to know if this can be fixed or if my approach/understanding is wrong.

Suppose I have a CreateEgg page, which has a form on it, and once the form is filled in and submitted the user is taken to a ListEggs page with the new egg in it.

So my egg controller will look some thing like this:

public class EggController : Controller
{
    public void Add()
    {
        //do stuff

        RenderView("CreateEgg", viewData);
    }

    public void Create()
    {
        //do stuff

        RenderView("ListEggs", viewData);
    }
}

So my first page will have a url of something like http://localhost/egg/add and the form on the page will have an action of:

using (Html.Form<EggController>(c => c.Create())

Meaning the second page will have a url of http://localhost/Egg/Create, to me this is misleading, the action should be called Create, because im creating the egg, but a list view is being displayed so the url of http://localhost/Egg/List would make more scene. How do I achieve this without making my view or action names misleading?

+4  A: 

The problem is your action does two things, violating the Single Responsibility Principle.

If your Create action redirects to the List action when it's done creating the item, then this problem disappears.

Brad Wilson
A: 
Dan
A: 

How A Method Becomes An Action by Phil Haack

Matt Hinze