I am having a base model as:
namespace MyNamespace
{
public abstract class ViewModelBase
{
public string Environment { get; set; }
}
}
I have 2 other models as:
namespace MyNamespace
{
public class ErrorViewModel : ViewModelBase
{
public string Error { get; set; }
}
}
namespace MyNamespace
{
public class SetPageViewModel : ViewModelBase
{
public string Name {get; set;}
public string Address { get; set; }
}
}
I am using this in my controller as:
public IActionResult Index()
{
var tuple = new Tuple<ErrorViewModel, SetPageViewModel>(new ErrorViewModel(), new SetPageViewModel ());
// tuple.Item1.Environment = "Dev";
return View(tuple);
}
With the above settings I want to have the below in my view to access these models:
@model Tuple<ErrorViewModel, SetPageViewModel>
But I keep on getting the error:
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'System.Tuple`2[MyNamespace.ErrorViewModel,MyNamespace.SetPageViewModel]', but this ViewDataDictionary instance requires a model item of type 'MyNamespace.ViewModelBase'.
I have tried the following:
Commented out the view part where I define my tuple to see if the error goes but no, I still get this error.
For both models I tried to remove ViewModelBase ie not to inherit from the base model but I still the above error.
Not sure what else am I missing here.