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 th开发者_Python百科e 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.
精彩评论