mcintyre321 / FormFactory

MVC5, Core or standalone - Generate rich HTML5 forms from your ViewModels, or build them programatically
http://formfactoryaspmvc.azurewebsites.net/
MIT License
304 stars 102 forks source link

How to add editable collection in Programatically created form? #84

Open TonyWoo opened 5 years ago

TonyWoo commented 5 years ago

Thanks for provided so great library, just has a question, how to add editable collection in Programatically created form?

mcintyre321 commented 5 years ago

Something like:

var formModel = new[]
            {
                    new PropertyVm(typeof(List<Movie>) , "movies")
                    {
                        DisplayName = "Movies",
                        NotOptional =true,
                        Value = new List<Movie>()
                        {
                             new Movie() {Title = "Fight Club"},
                             new Movie() {Title = "The Silent Partner" },
                             new Movie() {Title = "Bambi"},
                        }                        
                    },
};

...

    public class Movie
    {
        [Required]
        [StringLength(64, MinimumLength = 2)]
        public string Title { get; set; }
    }
mcintyre321 commented 5 years ago

It's a bit more complex if you want to have a list of programatically created types, rather than a static type (like Movie).

TonyWoo commented 5 years ago

Thanks for you quick reply @mcintyre321. I'd like build a form builder and user want to add some collection data. It seems the item type like Movie should be static type, not sure how to do it dynamically. thanks.

mcintyre321 commented 4 years ago

Did the above work for you?