部分视图菜单-发送信息以查看 [英] Partial view Menu - Send info to view

查看:59
本文介绍了部分视图菜单-发送信息以查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我尝试获取包含类的视图的方式.我得到它的方式是通过编写:

That's how I try to get a view that includes a class with. The way I get it on it is by writing:

@Html.Partial("View/ViewBar_Info/Menu")

如果我正在执行普通的MVC视图,则可以执行此操作.但这是因为我必须获得通过数据库控制的菜单.因此,我尝试在这里执行此操作.

If I'm doing an ordinary MVC view, I can do that. but that's because I have to get the menu that is being controlled via the database. Therefore, I try to do this here.

如何调用该视图?

错误文字:

在编译处理该请求所需的资源期间发生错误.请查看以下特定的错误详细信息,并适当地修改您的源代码.

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.

生成的代码缺少一个或多个编译参考.确保您的项目引用了"Microsoft.NET.Sdk.Web",并且"PreserveCompilationContext"属性未设置为false.

Generated Code One or more compilation references are missing. Ensure that your project is referencing 'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false.

更新EIDT:

我是通过_Layout.cshtml

I make this from _Layout.cshtml

@Html.Partial("View/ViewBar_Info/Menu.cshtml")

在Menu.cshtml中:

in the Menu.cshtml:

@page
@model NewWebsite_SITE_2018.Pages.View.ViewBar_Info.MenuModel

@foreach (var item in Model.GetListMenu)
{
    <a>@item.Name</a>
}

现在出现错误:

InvalidOperationException:传递到ViewDataDictionary中的模型项的类型为'NewWebsite_SITE_2018.Pages.IndexModel',但是此ViewDataDictionary实例需要一个类型为'NewWebsite_SITE_2018.Pages.View.ViewBar_Info.MenuModel'的模型项.

InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'NewWebsite_SITE_2018.Pages.IndexModel', but this ViewDataDictionary instance requires a model item of type 'NewWebsite_SITE_2018.Pages.View.ViewBar_Info.MenuModel'.

我想做的是在我的布局中,所以我将调用菜单,因此位于单个页面上.

What I'm trying to do is in my layout, so I'll call my menu so come on the single page.

推荐答案

第一个问题是2.0.3版中修复的Razor预编译问题. https://github.com/dotnet/core-setup/issues/2981

First problem has been in Razor precompilation issue that fixed in 2.0.3 https://github.com/dotnet/core-setup/issues/2981

第二

当您调用粒子时,如果不发送剃刀,则应向其发送正确的模型

When you call your partical you should send correct model to it if you not send razor try to send current model of view

发送现有模型

@ Html.Partial("View/ViewBar_Info/Menu.cshtml",yourMenuModel)

或创建新

@ Html.Partial("View/ViewBar_Info/Menu.cshtml",新的NewWebsite_SITE_2018.Pages.View.ViewBar_Info.MenuModel())

或修改非必需模型的视图

or modify your view for non required model

@{
var menuModel = new NewWebsite_SITE_2018.Pages.View.ViewBar_Info.MenuModel();
}

@foreach (var item in menuModel.GetListMenu)
{
    <a>@item.Name</a>
}

这篇关于部分视图菜单-发送信息以查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆