Show multiple models in a single view using ViewModel in Razor MVC3 (with only Details in view)

前端 未结 2 1540
半阙折子戏
半阙折子戏 2021-01-19 20:09

My task is to show multiple models into a single view.I\'ve created a ViewModel for my requirement but I\'m not meeting my requirement. please have

相关标签:
2条回答
  • 2021-01-19 20:36

    In your controller, define your action method as follows.

    public ActionResult ParentsDetails()
    {
        var studentDetails = new List<StudentDetail>();
        var parentDetails = new List<ParentsDetail>();
    
        // Fill your lists here, and pass them to viewmodel constructor.
        var viewModel = new ParentsInformationViewModel(studentDetails, parentDetails)
    
        // Return your viewmodel to corresponding view.
        return View(viewModel);
    }
    

    In your view define your model.

    @model MySolution.ViewModels.ParentsInformationViewModel
    
    0 讨论(0)
  • 2021-01-19 20:53

    Is there in your view declared that you are receiving model of type

    In view:

    @model IEnumerable<ParentsInformationViewModel>
    
    0 讨论(0)
提交回复
热议问题