Save a list of objects mvc5

我只是一个虾纸丫 提交于 2019-12-11 21:42:21

问题


I have the following object:

public class CarModelList
{
    public List<CarModel> CarsList { get; set; }
}

The CarModel is as follows:

public class CarModel
{
        public long Id { get; set; }

        public string Color { get; set; }

        public List<SelectItem> ColorList { get; set; }

        public string Seats { get; set; }

        public string Model { get; set; }

        public string Year { get; set; }

}

I have a view which on loading first displays 3 checkboxes : Sea, Air, Soil. If one checkbox is checked a tab is shown with the CarModel properties.
Depending on the checkboxes checked(Sea, Air or Soil), different CarModel properties will be displayed. For eg, if Air is checked the Seats will not be shown or if Sea is checked the Model is not shown.
The properties of the different CarModel ar shown in tabs. So if Sea is checked then the CarModel properties will be displayed in a tab excluding the Model property.
Then when Air is checked another tab is open to display the properties of the CarModel excluding the Seats property.
In my view I have only one submit button to save the CarModel.
So I thought of creating a Model containing a list of CarModel for the display and saving. Thus upon checking a new checkbox, the new CarModel is added to the list, CarModelList.
Any idea of how to proceed with the saving and validation of this CarModelList?

来源:https://stackoverflow.com/questions/51132013/save-a-list-of-objects-mvc5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!