views:

567

answers:

2

I'm developing my first ASP.NET MVC application. This application tracks events, users, donors, etc. for a charitable organization. In my events controller I support standard CRUD operations with New/Edit/Show views (delete is done via a button on Show view). But I also want to list all of the events.

Is it better to have a List view that you navigate to from an Index view or have the "List" view be the Index view. The Index view is my default view for the controller. If you keep Index/List separate, what would you put in the Index view?

Right now I'm leaning toward keeping them separate and putting basic help information on the Index view. Should I consider changing this and have the List view become the default view and rename Index to Help?

TIA for the collective wisdom of SO.

A: 

Your Index view page could include

<body>
    <% RenderPartial("List", "Events") %>
</body>

which is equivalent to calling

/Views/Events/List.ascx

with the List view being an asp.net mvc user control. That will give you an Index view which contains a list of events.

Todd Smith
My question was really should the index be the list or something else, not how do I get a list as my index.
tvanfosson
My answer is suggesting that your index not "be" the list but should include a list via renderpartial. Your list should be provided by a separate action method. That will give you greater flexibility down the road.
Todd Smith
A: 

I've decided to have the Index action redirect to the List action. This saves me from having to create and maintain an Index view, but leaves open the possibility that I can implement an Index action that is something other than the list of models.

public ActionResult Index()
{
    return RedirectToAction( "List" );
}
tvanfosson