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

给你一囗甜甜゛ 提交于 2019-12-01 18:35:24

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

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

In view:

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