tags:

views:

113

answers:

4

is there any particular directory that i should put my code into in an asp.net mvc project

i have some extentions to the HtmlHelper class. Right now i have it sitting in the Content folder. is this correct? is there a better soluiton?

+10  A: 

I usually create a separate project (or projects) for my own code, including my data layer, as class libraries. I then reference the libraries in my MVC web site.

tvanfosson
Indeed - That's what I'd do also.
Colin Mackay
+1 That's the way to do it.
Andrew Hare
+1!
Andrei Rinea
You advocate putting HtmlHelper extensions in a data layer?
Zack Peterson
No -- I advocate using separate libraries for your own code. My helper extensions would go in a MVC libary. My data layer would go in a different library.
tvanfosson
+3  A: 

you can put code wherever you want, but typically you want things organised. heres how i do it:

2 assemblies

  • MyProject.Domain

this contains all my domain code; business logic and entities

  • MyProject.Web

this contains controller code, views and assets like css/images

Your HtmlHelpers belong in the .Web project because they are mvc related (nothing to do with the domain). You probably want a new folder called Helpers or Extentions. Its really up to you, the key point is to decide where something belongs and to namespace it accordingly

Andrew Bullock
+1  A: 

If you are going to re-use the same HTMLHelper extensions in different ASP.NET MVC projects, I'd suggest putting them in a class library which is completely seperate from your project.

Adrian Grigore
+1  A: 

I agree with what everyone else said, here's how one of my solutions would look like:

  1. 1- MyProject.WebUI
  2. 2- MyProject.DomainModel
  3. 3- MyProject.Test
  4. 4- MyProject.Extensions

This extensions project is new to me (actually since I knew about extension methods). It usually concludes sub-folders describing what the extension methods are used for, for your particular case, the folder name would be HtmlHelpers. I then reference this project (or its output library when using elsewhere).
HTH

Galilyou