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?

4 Answers 4

14

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Indeed - That's what I'd do also.
You advocate putting HtmlHelper extensions in a data layer?
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.
4

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

Comments

2

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.