asp.net mvc - How to create, not edit, an object with a list of objects in C# MVC 4 using model binding? -


say had website users create (and edit) video game consoles. has following model.

videogameconsole:   string name   datetime released   list<videogames> games  videogame:   string name   datetime released   httppostedfilebase image 

(i hope example simple enough.)

i'm wondering how create such object using model binding (not edit, i've seen lot of solutions rendering or editing existing dynamic list). current way seems model binding allows create videogameconsole no games, go on edit screen , add games. i'm looking solution user can see total object before creation. @ least, there name i'm trying make easier continue own research on this?

thanks.

edit 1:

two important notes makes more... fun (in dwarf fortress sense).

first, i've changed model include httppostedfilebase each videogame represents image. need able upload multiple files. doesn't make more fun on own.

second, needs work without javascript (part of userbase of our apps has javascript disabled for... reasons... , can't not support them). real fun begins.

as not using javascript, partial solution follows.

when click add new game, post page back, not save it, , return view model page offering ability edit list of added games or add new one. stateless, except on each post add image file session (otherwise they'll have re-add every file every time decide add new game before hitting save). add javascript on top make intermediate postbacks not needed if have javascript enabled.

you've got examples editing existing model say, use guide , in create action, create , send down non-null model view, 10, 20, 100 (whatever number suits) of child items pre-populated, , prevent user adding new child items on , above you've provided in create view.

on postback, can check validity of child items, discard you'll not want keep - haven't been modified user.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -