0

I have a question about the MVC in the ASP.net Core world.

I have a userModel with data about my user and a Model with some useractivities. Like what they bought and when they bought it etc.

I want to create a dashboard for every user. So that i can see what they bought, how much they bought. E.g. bought in a month in percent. My Question is how do i implement this in ASP.net core MVC.

Do i have to put the Logic for the percent calculation in the Controller and return it to the view with a viewbag?

Or do i have to create a Model with that informations? Example:

UserStatsModel

Int UserID

String Name

Double OrdersPerMonth …

And return this Model to the View?

Or is both valid?

  • Have you done any tutorials concerning MVC? – Grizzly Nov 29 '16 at 14:25
  • Thanks for your response. Yes I have done. I'm just confused. I would do the Logic for the Calculation in the Controller. I have the Logic for User Add, Delete, Update etc in de UserModel. I Could easily use the UserManager in the Controller to get the repository. My Problem is, that every tutorial says, that the Logic have to be in the Model at its best. This is what confuses me in ASP.net core. Or do I missinterpretend this? – M.Millia Nov 29 '16 at 14:31
  • I'm just asking to be sure. – M.Millia Nov 29 '16 at 14:37
  • If you simply want to calculate a percentage.. using the properties that you defined in your Model.. then you can do that in the controller, and return that object to the view. No need for a ViewBag. – Grizzly Nov 29 '16 at 14:40
  • Thx for the response. The Problem is, that I have two and later three Models, which a relevant. But I can only return one Model. This is where I'm stuck. I have a User (I need the Name in the View) I have every Order with product, date, price etc. in the UserOrderModel. (I want return e.g. AllOrders for October Sum) and so on and I want to calculate, combine them and return to a view. – M.Millia Nov 29 '16 at 14:44
  • This is where you need a [ViewModel](http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc).. which it's only purpose is to display what you want to show the user. – Grizzly Nov 29 '16 at 14:47
  • So this answers my question. I was starting with a viewModel. I just wasnt sure which of both possibilities is the right choice. You showed me the way. Thank you! – M.Millia Nov 29 '16 at 14:52
  • Good [LINK here](http://stackoverflow.com/questions/11969964/should-sorting-logic-be-placed-in-the-model-the-view-or-the-controller?rq=1) for people with the same problems like me – M.Millia Nov 29 '16 at 14:58
  • You're welcome. I'm glad I could help. – Grizzly Nov 29 '16 at 15:08

0 Answers0