I am working with a PartialView that is used in two different views, each utilizing its own viewmodel. On one of the views, the code looks like this:
view1:
@model StudentsViewModel
......
.....
@Html.Partial("_StudentOtherInformation")
PartialView
@model StudentsViewModel
@if (Model.StudentList != null)
{
<input type="hidden" id="firstStudent" value= "@Model.StudentList.ElementAt(k-1).StudentID" />
}
view2:
@model SearchViewModel
....
@Html.Partial("_StudentOtherInformation")
When trying to access the viewmodel of view1 within the partial view, I encountered an exception due to confusion between viewmodels. After some research, it seems creating a parent viewmodel containing both individual viewmodels is one solution. However, the challenge lies in the fact that these two viewmodels are in separate namespaces. Is there a way to pass the corresponding viewmodel to the partial view from each of the views?