I have a View with 2 DropDownListFor. This View is loaded with a certain ViewModel. The flow demands that when the user selects an Item from the second DropDownListfor, present in the View, another DropDownListFor must show with other data. To solve this I used a PartialView, obtained using a ajax request, with a different ViewModel just for this PartialView. Now the problem is how can I submit data from the View and the PartialView using a ViewModel and not FormsCollection? Is having two different ViewModels the correct way to tackle this kind of problem? Every example shows the use of only one ViewModel per View but what happens if the Data of that ViewModel isn't all loaded when the View is created?
I created a PartialView and specific ViewModel for it. To be able to submit only the MainViewModel with all data, I had to create the same property on both the ViewModels of the View and PartialView. But does this makes sense?
public class AlertViewModel
{
public string AlertDescription { get; set; }
public List<DropdownModel> AlertTypesList { get; set; }
public long SelectedAlertType { get; set; }
public List<DropdownModel> CustomersList { get; set; }
public long SelectedCustomer { get; set; }
public long[] SelectedProducts { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
public class AlertProductListViewModel
{
public long[] SelectedProducts { get; set; }
public List<DropdownModel> ProductList { get; set; }
}