0

I scaffolded a CRUD scenario for my model to start from. Now I need to add a radio button list field (which doesn't exist but the scenario for a dropdownlist is the same so think of that) for one field (an association to another type, think of a foreign key) to my "create"-view with database driven listitems. I found no other way to do this (without losing my strongly typed view) then to wrap my whole model in another one so I can add the list items.

That means I have to adapt almost every line in the view because they are no longer:

@Html.EditorFor(model => model.Name)

but now:

@Html.EditorFor(model => model.Model.Name)

Is there no way around this?

Koen
  • 3,626
  • 1
  • 34
  • 55
  • Why don't you pass them in a ViewBag ? This way you can keep your model and just use the ViewBag.YourItems where you need the list of items (es SelectList). – Giorgio Minardi Apr 06 '12 at 15:43
  • Because I'd like to keep my views strongly typed... – Koen Apr 06 '12 at 15:51
  • Well there's not really any other choice then, you need to extend your model. Btw, as you said, if the data you want to add doesn't belong to your model (a list of items) it is correct to store it in another place rather than the model itself. The ViewBag then is a good option. – Giorgio Minardi Apr 06 '12 at 15:56
  • I already thought scaffolding doesn't go a long way. Pity... – Koen Apr 06 '12 at 16:00

0 Answers0