首页 > 解决方案 > 当我将此部分视图用于我在 mvc 中使用两个类的元组的视图中时,如何将 basemodel 类传递给部分视图

问题描述

我有一个视图,其中我使用两个类的元组来呈现它。

@model Tuple<SAP.DTO.ViewData.IndentmstViewData, SAP.DTO.ViewData.IndentdetViewData>

我正在从控制器传递数据

            IndentmstViewData model1 = new IndentmstViewData();
            IndentdetViewData model2 = new IndentdetViewData();
            var model = new Tuple<IndentmstViewData, IndentdetViewData>(model1, model2);
            model.Item1.GetMenuData = GetMenuByUser();
            return View(model);

但是在我的布局页面中,我使用了部分页面来呈现菜单,使用了部分页面模型:

@model SAP.DTO.ViewData.BaseViewData

当我运行应用程序时,它会引发错误:

传入字典的模型项的类型为“System.Tuple`2[SAP.DTO.ViewData.IndentmstViewData,SAP.DTO.ViewData.IndentdetViewData]”,但此字典需要类型为“SAP.DTO.ViewData”的模型项.BaseViewData'。

标签: c#asp.net-mvc

解决方案


推荐阅读