asp.net-mvc – 使用@ Html.Partial渲染usercontrol(cshtml)
发布时间:2020-12-16 04:02:45 所属栏目:asp.Net 来源:网络整理
导读:我正在接触MVC 3并且很困惑我如何在我的项目中使用UserControls. 我创建了一个名为UserControl.cshtml的usercontrol(cshtml)文件,我正在尝试将其呈现为Products.cshtml. MyUserControl.cshtml位于Shared文件夹中. 在Products.cshtml中: div @Html.Partial("
我正在接触MVC 3并且很困惑我如何在我的项目中使用UserControls.
我创建了一个名为UserControl.cshtml的usercontrol(cshtml)文件,我正在尝试将其呈现为Products.cshtml. MyUserControl.cshtml位于Shared文件夹中. 在Products.cshtml中: <div> @Html.Partial("MyUserControl.cshtml"); </div> 但是我收到了这个错误.我不知道为什么要搜索.ascx文件: The partial view 'MyUserControl.cshtml' was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Products/MyUserControl.cshtml.aspx ~/Views/Products/MyUserControl.cshtml.ascx ~/Views/Shared/MyUserControl.cshtml.aspx ~/Views/Shared/MyUserControl.cshtml.ascx 这是在mvc 3中呈现usercontrol的正确方法吗? –Update– 这有效. @RenderPage("../Shared/MyUserControl.cshtml") 解决方法
您不需要指定文件扩展名,视图引擎将处理该文件扩展名.
@Html.Partial("MyUserControl") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- asp.net-mvc – MVC调用Html.Action在区域内?
- ASP.NET MVC3 RC2从请求参数绑定到方法参数的bug
- asp.net-mvc-3 – 在DEBUG或Debugger中运行时禁用
- asp.net-mvc-3 – 如果没有定义,Razor RenderSec
- asp.net – visual studio调试错误无法启动程序没
- 是否可以运行异步调用来在ASP.NET中设置会话?
- asp.net-mvc – 带有并发检查的ASP.NET MVC实体框
- .net – MVC6的VersionedRoute属性实现
- asp.net – 在IIS7上设置虚拟目录
- ASP.NET MVC捆绑缓存. (检测css文件更改)(内部行
热点阅读