Sagick
Sagick

Reputation: 327

How do I properly structure an mvc set of views to minimize the number of views for many models?

I've spent the last month trying to figure out how to code a b2b2c (buisness to buisness to consumer) website. After combing over a lot of asp.net documentation, the way they have you create views, is to create a series of views for each model you have. this works fine until you find yourself creating more than 5-6 models.

for example my views folder currently looks like this:

current views folder strucutre

I'm aware these are razor pages which are probably bad if i have a lot of models and need to organize my views to get from one or a few controllers. but if i were to create views for models the way the documentation reccomends, I end up with 5 views for a models, meaning if i have 10 models I have 50 views which is a lot to code if i want to tweak them at all.

I've tried going to both of these links while doing my own research, and boostrap has been suggested to me as a way to create some sort of structure.

MVC - Model - View Model Structure https://visualstudiomagazine.com/articles/2015/07/01/structuring-views.asp

but at the end of the day i'm still quite lost on how to refactor all of this.

Upvotes: 0

Views: 225

Answers (1)

Kevin
Kevin

Reputation: 333

From my understanding of how MVC works the reason they want you to make ViewModels for each separate view is to abstract out the actual functionality of your website. You can also use a ViewModel for several different views if the required attributes are the same. I suggest looking into KendoUI to help minimize your number of views if that is your concern. Overall, MVC allows a easily understandable way to organize your website to be maintainable in the long term. While it may take a bit longer to develop because you have to create more ViewModels and spend a decent amount of time organizing it should reduce the amount of total work you will have to do in the long term.

Upvotes: 1

Related Questions