I have the following class which encapsulate a list of SelectListItem
and an instance of ViewModel
public class SwitchCampaignCapsule
{
public TrackEmployeeSwitchStageViewModel ViewModel { get; set; }
public List<SelectListItem> Stages { get; set; }
}
Then I have a presentation class which encapsulate the SwitchCampaignCapsule
along with other stuff that I removed for the sake of the simplicity.
public class TrackPresenter
{
public SwitchCampaignCapsule SwitchCampaignCapsule { get; set; }
....
....
....
}
I pass the Proj.TrackPresenter
class to my main view. Then in the main view I am trying to pass the Model.SwitchCampaignCapsule
in a partial view.
Here is how my main view looks like
@model Proj.TrackPresenter
@{
ViewBag.Title = "Time Tracker - Track";
}
@Html.Partial("Partials/_TrackSwitchStage", Model.SwitchCampaignCapsule)
....
....
....
and here is my partial view
@model Proj.Capsules.SwitchCampaignCapsule
@using (Html.BeginForm("SwitchStage", "Track", FormMethod.Post, new { @class = "form-horizontal" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(m => m.ViewModel.From, new { @class = "tracker-selected-date" })
@Html.HiddenFor(m => m.ViewModel.LocalFrom, new { @class = "tracker-local-selected-date" })
<div class="form-group">
@Html.LabelFor(m => m.ViewModel.StageId, new { @class = "col-sm-2 control-label" })
<div class="col-sm-10">
@Html.DropDownListFor(m => m.ViewModel.StageId, Model.Stages, new { @Class = "form-control" })
@Html.ValidationMessageFor(m => m.ViewModel.StageId)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary style-my-form-for-validation" id="TrackSwitchStageSubmit">Switch stage</button>
</div>
</div>
}
But when I run the application, I get the following error
The model item passed into the dictionary is of type 'Proj.TrackPresenter', but this dictionary requires a model item of type 'Proj.Capsules.SwitchCampaignCapsule'.
I am not sure why am I getting this error. it is very clear that I am passing Model.SwitchCampaignCapsule
to the partial view and not Model
What am I missing here? Why am I getting this error? How can I fix it?