Alex Rivera | Logout

ASP.Net MVC View Structure

Asked 2009-04-21T14:32:30.877
11

I just finished Scott Gu's Nerd Diner tutorial. I found it very helpful because it not only taught the basics of ASP.Net MVC, but also how to use with Repositories, Validation, Unit testing, Ajax, etc.. Very thourough, but still manageable.

However, I am curious about his site structure:

Specifically, he used this view strucuture for every object:
/ModelObject/Edit/
/ModelObject/Create/

Then extracted the common elements between the two views and put them into a partial.

I understand the logic, but it seems like it would lead to "view explosion" if you have even a moderate number of tables in your database.

Scott's really good, so I am assuming his structure is right. But I would like to know why.

Thanks!

[Edit for clarification]

I realize that many times it is necessary for there to be multiple actions (and views) to handle differences in creates and edits. It is the case of the very simple edit and create, where the only difference between the two actions is in one case the model has an ID and needs to be updated, and in the other case the model does not, so it needs to be inserted.

In this case, is the violation of the "Dumb View" rule by using the same view to handle both cases going to cause major problems?

Edit
Report

1 Answer

1

On more reflection, this is what I am thinking:
Combining the edit/create views would be easy on simple models because

    - Same properties displayed
    - Same validations

BUT doing this would force you to either

    - handle both the update and insert in the same action
    - use a control statement in the view to determine which view action is used to update

Both options seem ugly and unnecessary when it is so easy to use separate actions and separate views with common code extracted into a partial.

answered 2009-04-23T12:33:27.993

Your Answer