Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In asp.net-mvc, what is the best way to deal with a crowded Shared View folder?

I have a large ASP.NET-MVC project and I have a lot of files in the shared View folder.

I want to group these files (Views) to make it easier to understand. I saw this blog post which seems to have the same issue but I would like to avoid an additional dependencies / dll in my solution.

Is there anyway to organize the Shared Views directory without any external dependencies. I am using the aspx View Engine (NOT Razor)

like image 566
leora Avatar asked Jan 26 '26 01:01

leora


2 Answers

In ASP.NET MVC, sharing works in multiple ways.

1) Use the Controller's View Folder.

Yes, View Engine will always check you Shared folder for a partial view. But before checking the shared folder, the View Engine will check the "active" folder.

So to explain in better detail, take a scenario where you are using HomeController, rendering a View in the "Home" View folder, and you are rendering a Partial View called "NavPartial". Before checking your "Shared" folder for the Partial View, the View Engine will check your "Home" View folder first.

This means that if you need to re-use Partials within a Controller, you can pack them into that Controller's dedicated View Folder.

I find this approach convenient. I organize my project and Controller structure to take advantage.

2) Use Areas

If you use Areas, each Area has a dedicated "Shared" folder. This is again convenient if your functionality is local to that Area.

like image 173
Dave Alperovich Avatar answered Jan 27 '26 19:01

Dave Alperovich


that is for what for asp.net mvc is , all can be customizable.

you can do things like this where your structure looks like

Folder Structure

this is about displaying templates

to display use

@Html.Display("","Home/Managable",null)

Display is helper extension method that find the partial view and render..

if you want editor based then you can use Editor Templates and Extenstion method is Editor , EditorFor etc..

Example here is in Razor but same applies to aspx view engine also..

like image 28
Vishal Sharma Avatar answered Jan 27 '26 18:01

Vishal Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!