Render usercontrol (cshtml) using @ Html.Partial

I get my hands on MVC 3 and am confused about how to use UserControls in my project.

I created a usercontrol (cshtml) file called UserControl.cshtml and I am trying to make it Product.cshtml.

MyUserControl.cshtml is located in the shared folder.

In Products.cshtml:

<div> @Html.Partial("MyUserControl.cshtml"); </div> 

But I get this error. I do not know why it is trying to find the .ascx file .:

 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 

Is usercontrol in mvc 3 doing this right?

- Update -

It works.

 @RenderPage("../Shared/MyUserControl.cshtml") 
+6
source share
2 answers

You do not need to specify a file extension whose handler will process it.

 @Html.Partial("MyUserControl") 
+14
source

Phil haack has a fantastic partial page blog.

http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx

+2
source

Source: https://habr.com/ru/post/890947/


All Articles