I would like to have in the registration form in my site an interface. lets call it IShape.
there are serval interface implementations, like ISquare and ICycle,
each one has its own properties except the shared ones declared in the interface.
I want the user to have the ability to have as many shapes as he wants from all types posssible,
and be able to fill them with information, which I receive as RegisterModel.
public class RegisterModel
{
[Required]
[Display(Name = "Username")]
public string UserName { get; set; }
[Required]
[Display(Name = "Shapes")]
public List<string> Shapes { get; set; }
}
Register Action:
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Iterate over the shapes
model.Shapes ...
}
}
Please refer to the javascript issue, since if I have multiple objects their names will conflict.
For example: 2 shapes has size property. if I create two textboxes with the name “size”,
The ASP.NET engine won’t be able to solve it.
Thanks!
I would look at using Knockout.js for the front end to allow the user to construct their list of objects. It is an MVVM framework that lets you manage client side events and manipulate the DOM.
You could send an ajax request back to the server for each new shape they add (on the onclick event). You would need to then persist the list the user is building up in the database or session, but when the user hits confirm/submit you would already have access to the full list so it will be easy to perform validation on all the items at once.