Answer the question
In order to leave comments, you need to log in
MVC - Use one model per Profile page or split into several?
Good afternoon.
I ask for advice.
In the project, there is a profile page.
On the profile page, you can view / change user data, such as full name, date of birth, city, etc.
You can also change settings on the page, such as receiving notifications on VK, FB, email.
You can also change your password on this page.
All these data groups are divided into 3 blocks: information, settings and password change. Each block is a separate form with its own submit button that calls a separate controller method.
In the database, this is a single AspNetUser entity. At the beginning, it seemed to me more logical to divide one model into 3, for respectively independent changes in user data, settings and password. I did everything on separate pages. Now I think to unite everything on one. But then it's easier to use one model. And accordingly one html form. And, accordingly, one controller method.
A little confused with the creation of models. Can you tell me how best to approach the creation of models when working with web pages that are supposed to separate blocks of data changes (for example, user data in one form, notification settings in another)?
What can you see or read about this?
Answer the question
In order to leave comments, you need to log in
I made one model for displaying the view and several models for changing each of the sections of the profile. Accordingly, we got several controller methods with different incoming models to change their data block.
As a vartant, the model implements the functionality of a single object. Those. the user is an object and it is logical to conclude all operations connected with it in one model. Or each table in the database corresponds to one model that contains all the necessary functionality to work with it. And the controller can connect as many models as needed. A matter of taste.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question