1

I have my view 'Create.cshtml' in folder Views-Department. I want to use partial view which is located in folder on root, 'CommonViews' with the name '_EnterpriseStructure.cshtml'. I am using syntax RenderPartial

 @{Html.RenderPartial("~/CommonViews/_EnterpriseStructure.cshtml");}

Partial view code

<div id="Client">
   This is a Partial View.
</div>

When executed I am getting System.InvalidOperationException.

Detail error is:

The view at '~/CommonViews/_EnterpriseStructure.cshtml' must derive from WebViewPage, or WebViewPage.

I am using ASP.Net MVC 5 Razor Views

tereško
  • 58,060
  • 25
  • 98
  • 150
pkp
  • 11
  • 2
  • Possible duplicate of [The view must derive from WebViewPage, or WebViewPage.](http://stackoverflow.com/questions/8127462/the-view-must-derive-from-webviewpage-or-webviewpagetmodel) – Dai Oct 03 '15 at 10:55

2 Answers2

0

I have found that Razor view engine is searching in folders 'Views/Shared', 'Views/Departments' . When I moved the Partial View, to folder 'Shared' it worked. You cannot include path, you just have to give View name. And add folders to search for View engine. What I cannot figure out is "How to give more Search locations to View Engine?"

pkp
  • 11
  • 2
  • Refer [this answer](http://stackoverflow.com/questions/632964/can-i-specify-a-custom-location-to-search-for-views-in-asp-net-mvc) –  Oct 03 '15 at 11:46
0

I would reckon you to use T4MVC nuget package in your MVC project. Once the package is included in your project, you just need to select "T4MVC.tt" file in your project (solution explorer) and say "Run Custom Tool". That's it. This will create constants for almost everything in your MVC project. That means, all views, controllers, actions, javascript files, resources, css files, images, etc are now having constants.. This way you can avoid using the hard-coded strings for views etc in your methods, and can use constants generated by T4MVC. You won't need to worry about path of views etc. T4MVC is very effective and is must for MVC projects.

Nirman
  • 6,715
  • 19
  • 72
  • 139