我正在接触MVC 3并且很困惑我如何在我的项目中使用UserControls.
我创建了一个名为UserControl.cshtml的usercontrol(cshtml)文件,我正在尝试将其呈现为Products.cshtml.
MyUserControl.cshtml位于Shared文件夹中.
在Products.cshtml中:
<div> @Html.Partial("MyUserControl.cshtml"); </div>
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")