RAHUL NATH

RAHUL NATH

  • NA
  • 23
  • 410

Pass viewmodel (contain List<ModelClass>) data to controller

Aug 20 2018 8:12 AM
In my application there is an edit page, which contains a list of data through a viewmodel. this viewmodel contains two list, i.e. List<ModelClass1> and List<ModelClass2>.
 
In the view, there are multiple row of data from the lists, and i want to edit the rows and send to the controller to save the data. For this, i am usuing - @using (Html.BeginForm("Submit", "ControllerName", FormMethod.Post)) {-----}
 
however, on submit button press, when the control moves to the action method, there i found, the data is retrieving as null. below is the action method - 
public ActionResult Submit(ViewModel _ViewModel)
{
// 
with a debug point, i found the view model is null for both the list.
below is the view model class - 
public class ViewModel
{
public List<Model1> Model1List { get; set; }
public List<Model2> Model2List { get; set; }
 
could anyone let me know the way to pass the data to controller? 

Answers (2)