0

I'm new in MVC. I saw the most of article about dynamic form is just for client side interface like add form group dynamically not the new object. If it is possible, how about the Model? Can we make model has dynamic property based field on the database that has created/added dynamically and generate the View form layout from the controller for CRUD Operation?

namespace Web1.Models
{

    public class Class1
    {
        public string field1 { get; set; }
        public int field2 { get; set; }

       // Create dynamic property based database field that has been added
    }
}

Thanks in Advance

admfb
  • 11
  • As for 'dynamic property' you can use collection property for dynamically generated inputs. It's unclear what you're trying to do (requires clarification about 'dynamic property'). – Tetsuya Yamamoto Oct 26 '17 at 08:31
  • @TetsuyaYamamoto thanks for your response. 'dynamic property' means field collection in the table on database. If table has a new field, I would like the model can updating the entitiy class property for changes of the table. – admfb Oct 26 '17 at 08:41
  • @TetsuyaYamamoto Absolutely, Its right. Is it possible or imposible? – admfb Oct 26 '17 at 08:43
  • Well, do you want to add field3, field4, etc., with different types? I think you can use `ViewBag` to handle them (take a look at these: https://stackoverflow.com/questions/8926664/how-do-i-create-dynamic-properties-in-model-and-use-in-controller-and-view-mv & https://stackoverflow.com/questions/33847321/c-sharp-asp-net-mvc-dynamic-object-properties). – Tetsuya Yamamoto Oct 26 '17 at 08:48

0 Answers0