简体   繁体   中英

Asp.net mvc Parent/Child Create/Update View

What is the best practice for creating/updating the data using the following pseudo view:

parent name field
parent description field

table with child data:
    existing fields
    fields for child[1] with existing data
    fields for child[2] with existing data
    empty field[1] for a new child
    [add new child button (just creates the fields. no server contact)]

[save everything button]

Is there a best practice for child field naming conventions, how to load up some models in the controller, checking for updated data in the existing child models, so you're not just clearing out all of the children and then adding them again, etc. Lets assume I'm using linq to sql for my models. It doesn't seem like you can automatically bind the values (not the child ones anyway), and I'm sure there are some hacky ways to get the job done. But what's the best way?

Apologies in advance for sticking to generalities...

For a strongly typed view, you can only bind one model. It would make sense to just aggregate the child objects (like you are doing in your pseudo code). It doesn't really matter though, because with or without a strongly typed view, you can throw multiple random objects into ViewData as use them as you please.

So to me, it's really a matter of the cleanest way to map to your Business domain that's important. I like to think of the view as an interface to my domain classes.

As for naming conventions, name your classes and objects as you would any code that you want to be easily readable and maintainable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM