I am working on ASP.NET MVC 3 project. I want to divide controllers, models, and views in sub-folders for the sake of simplicity. I able to do it with controllers and models but when i create a view it creates automatically to root folder Views
, Is there any way to solve this problem?
eg. I can create
model class as,
Models/Finance/Bank.cs
Models/Finance/Finance.cs
Models/Production/Production.cs
controller as,
Controllers/Finance/BankController/Create
Controllers/Finance/BudgetController/Create
Controllers/Production/ProcessController/Create
but where i tried to create view for above actions, it creates in to,
Views/Bank/Create.aspx
Views/Budget/Create.aspx
Views/Process/Create.aspx
I want it should be like,
Views/Finance/Bank/Create.aspx
Views/Finance/Budget/Create.aspx
Views/Prodution/Process/Create.aspx
Is there any way to create views in same sub-folder as of that created for Controllers and models? thanks!
Best Answer
following steps worked for me,
Create sub-folders as you want in
Views
(root folder). in my case it was Finance & Production.Simply drag automatically created folders in
Views
in to appropriate Sub-folders. in my caseBank
&Budget
in toFinance
andProcess
in toProduction
While you return a view from controller action, give full path of view as,
return
View("~/Views/Finance/Bank/Create.aspx")
return
View("~/Views/Finance/Budget/Create.aspx")
return
View("~/Views/Production/Process/Create.aspx")