Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I create a controller that has a method ActionResult UploadFile(HttpPostedFileBase file) Where is the best place to add the code that will verify that this is a good and useable file? The reason I ask, is I will have to do more checking than just the file extension. For instance; check number of columns in spread sheet, check column names, etc..

share|improve this question

The best way i have found to determine when i should move code from the "presentation" to the "service" layer is by asking the question... if i change client (from mvc to winforms), is this code "reusable" by both client?

In your case, for example, the code that does a deeper validation, should be in the service layer, not the controller, so it can be used the same way by multiple clients. In other words, you don't have to rewrite it again. This method works for me and keeps my controllers skinny like an anorexic Victoria's Secret model :)

share|improve this answer
+1 for an inappropriate analogy – MVCylon Oct 4 '12 at 12:46
This method works for me and keeps my controllers skinny like an anorexic Victoria's Secret model :) This answer would benefit greatly from some pictures. But not of your code... :) – Gavin Coates Oct 22 '15 at 13:22

Does a method to check the file type being uploaded belong in the controller?

No, business logic belongs in the 'Service' layer.

Rule of Thumb with MVC:

Keep your models fat and your controllers skinny.

For more background, please see this thread.

share|improve this answer

You could read out the file stream in the controller and then pass the file to some business logic later which will handle more complex analysis.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.