I have page where I use model which can have different types (depending by action and controller). My problem starts when I want to use partial which take parameter from Model like:
@Html.Partial("~/Views/Components/SubMenu.cshtml", MyProject.Web.MenuHelper.GetSubMenu(Model.field1))
but, if I not declare type of model I have an error like Partial can not use dynamic values
. So I have idea to solve it with:
@if (Model.GetType() == typeof(ContentPage))
{
@model ContentPage
@Html.Partial("~/Views/Components/SubMenu.cshtml", MyProject.Web.MenuHelper.GetSubMenu(Model.field1))
}
else if (Model.GetType() == typeof(Data.Models.Directory))
{
@model Directories
@Html.Partial("~/Views/Components/SubMenu.cshtml", MyProject.Web.MenuHelper.GetSubMenu(Model.field2))
}
But then I have error like: ContentPage.field2 no exist
.
Do you have any ideas how can I solve it?
Any help would be appreciated.