tags:

views:

22

answers:

1

I have an object that contains a collection of items, each item being another object. In ASP.NET MVC, I'm a little unclear about how to go about using databinding in my "Create" Views for this collection, since each object in it has to be created new.

Any suggestions? Here is the schema.

Units
- UnitId

Rings
- RingId

Keys
- RingId (FK)
- KeyId (PK)
- KeyLiteral (FK)
- KeyValue

Literals
- LiteralId
- LiteralValue

and in the view...

<%= Html.DropDownList("Rank", new SelectList(... wut...) ) %>

It doesn't have to be a dropdown of course. I'm just lost because you see, at create time, the items don't exist. They are added by adding Keys to the "KeyRing" (Unit.Ring.Keys.Add). A Key expects a Literal and a Value to be added.

+1  A: 

What options do you want in the dropdownlist? Are they from DB or just an enum or something? Could they be passed down from the Controller?

In ASP.NET MVC, there is no need for "data binding" as such. Instead, you add form fields with names corresponding to the parameters of the action method you post to, and the model binder automagically puts the right values in each parameter. You can then use them as you like when saving to db.

Tomas Lycken
It doesn't really have to be a dropdown list, that was just an example. I'd like to be able to specify a new key, and have a form field for it, and when it returns to the controller be able to treat it as such within the Unit class that is returned.
Stacey
OK. Which entity is it that you're creating? Unit?
Tomas Lycken