1
votes

my problem is that I have a MVC4 project and I want to create some components that I want to add in some views using partial views. I will show you a picture of the folders logic that I want to create in my MVC project.

enter image description here

From this how can I add this partial views because when I try to acces them they are first looked in the main Views folder from my application, is there a way to make custum routes to my application?

@{ Html.RenderPartial("Components\\Chart\\View\\Index.cshtml");  }

This gives an error like this.

The partial view 'Conmponents\Chart\View\Index.cshtml' was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Home/Conmponents\Chart\View\Index.cshtml.aspx ~/Views/Home/Conmponents\Chart\View\Index.cshtml.ascx ~/Views/Shared/Conmponents\Chart\View\Index.cshtml.aspx ~/Views/Shared/Conmponents\Chart\View\Index.cshtml.ascx ~/Views/Home/Conmponents\Chart\View\Index.cshtml.cshtml ~/Views/Home/Conmponents\Chart\View\Index.cshtml.vbhtml ~/Views/Shared/Conmponents\Chart\View\Index.cshtml.cshtml ~/Views/Shared/Conmponents\Chart\View\Index.cshtml.vbhtml

1

1 Answers

1
votes

You can specify the path using ~ as the project directory.

Html.RenderPartial("~/Components/Chart/View/Index.cshtml",model)

Also this issue has nothing to do with the routing. Routing is about mapping incoming requests to your action methods. ASP.NET MVC tries to locate your views using controller and action names. If it's not there, it also check the Shared folder. You can override this behavior by specifying exact path, like in the example above.

Update:

Also you have to make some configurations to your View folder. Copying your Web.config inside the default Views folder or moving all view configurations to project's Web.config file should do the trick.