Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been coding for a few years and often end up with very busy Controllers and a few static helper methods. The code is stable and works fine, but can be a pain to comeback to after a few months and update. And I can't help but think I'm fighting with MVC rather then using it to its full potential.

I'm looking for a well written small open source c# MVC Project, that I can download and learn from. Ideally one that has Unit testing and uses Entity Framework.

So can anyone suggest a good project to learn from, or failing that a good book or online course?

What I have tried:

Looking at nopCommerce, but it is much to large.
Posted
Updated 28-Mar-18 2:46am

Try the Articles section here on CodeProject, or use Google to do a wider search.
 
Share this answer
 
Comments
Member 8741848 28-Mar-18 8:49am    
Do you have one (or some) that you can recommend? I've gotten myself in to this 'problem' by following poor/simple examples.
You can break your controller code into multiple files (you have to make your controller a partial class). I do this if the controllers are "busy". It helps to keep stuff compartmentalized a little more and you avoid having to scroll past methods that aren't applicable to what you're doing. I usually put non-decorated actions in the main file (stuff that doesn't have a get/post pair), and actions that DO have a get/post get their own file.

I also move my controller files to their respective view folders. This lets me find them without having to scroll to find the controllers folder and then find the controller file I want.

Of course, this kind of file organization may be restrained/prohibited by corporate coding style requirements, but I always do this for my own stuff.
 
Share this answer
 
v4
Comments
F-ES Sitecore 28-Mar-18 8:44am    
If your controllers are "busy" then rather than abusing partial classes you could always just move the business logic into the models where it's supposed to be :)
#realJSOP 28-Mar-18 9:32am    
It doesn't always belong in the models (uploading files for instance). It's just an organizational scheme, since most of the time, I'm simply updating the model in my post statements. "Busy" also means moderately complex redirects based on data provided by the user, or which button cause the post method to be called. So you see, it's not as cut/dried as you imply.
Member 8741848 28-Mar-18 9:38am    
I've had a few of these, where the controller is full dealing with various buttons even if the logic behind each on is rather simple. It's those types of things I would like to see in a open source project or book to see how I should have handled it.
#realJSOP 28-Mar-18 9:42am    
My answer was simply to let you know that you can move the controller files around within the project and utilize partial classes, and as long as you don't change the namespace, you're gold. It sounds to me like you just want to organize the files a little more to your liking. If I made an incorrect assumption, just ignore me. :)
#realJSOP 28-Mar-18 9:39am    
How is utilizing features of the framework considered "abuse"?
It also sounds like you've write a single monolithic controller handling everything. Reorganize the controller into multiple controllers handling a specific topic, like Login, Home page, ...
 
Share this answer
 
Comments
Member 8741848 28-Mar-18 8:59am    
It's normally split that way for the majority of my controllers, but in most projects I will end up with one controller that seams to keep growing. e.g. If I were to write something for a car dealer, my car controller would end up stuffed full of loads of different actions related to the cars. Or just a few action but with lines & lines of code.
It just seams not right, and I would like to review some well written / organised projects to see where I'm going wrong. Or start from scratch with a good book / course.
#realJSOP 28-Mar-18 9:38am    
It's a matter of personal organizational style. Remember, "best practice" isn't a hard/fast rule - it's just a guideline.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900