asp.net-mvc – 使用@ Html.Partial渲染usercontrol(cshtml)

我正在接触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")

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....