razor - 在 razor cshtml 文件中渲染 .ascx

标签 razor

我正在尝试在 _LayoutPage1.cshtml 中执行此操作:

@{ this.Html.RenderPartial("~/Views/Shared/Header.ascx"); }

但是,由于我在 Razor 中,intelicense 不会为 this.Html 显示“.RenderPartial”。

如果我在 .aspx 页面中,它效果很好。

我错过了什么吗? @using 指令?

谢谢!

最佳答案

至少需要将 System.Web.Mvc.Html 命名空间导入到 Views 目录下的 web.config 文件中。

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="YOURBASE">
        <namespaces>
            <add namespace="System.Web.Mvc.Html" />
        </namespaces>
    </pages>
</system.web.webPages.razor>

关于razor - 在 razor cshtml 文件中渲染 .ascx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5793930/

相关文章:

javascript - 如何在 Kendo UI TreeList/Grid 中获取一行?

c# - Razor MVC C#。替换 "."上的 ","

c# - 根据列值显示/隐藏 jQuery 数据表操作链接按钮

c# - 当前上下文中不存在名称 'ViewBag' - Visual Studio 2015

html - 通过razor从umbraco 6中的宏获取参数

sql - Webmatrix csv 导入到 SQL Server Compact

javascript - Razor 语法中的 "data"Ajax 选项在哪里?

c# - 获取 DropDownList 的选定值。 ASP.NET MVC

html - 如何在同一个表格TD中创建嵌套单元格

asp.net-mvc - Viewbag.Title 错误 : One or more types required to compile a dynamic expression cannot be found. 您是否缺少引用?