2

Let's say I have a form with a black label. I have a button that is supposed to change the label color to red.

This functionality has nothing to do with the data layer (the Model), but only with the View. So should the button click event be handled in the Controller or in the View itself?

2

Generally speaking - the controller.

I get the feeling you're omitting the technologies you're working with here. For example, if you were to say this was a HTML5 SPA app and controllers are all server side, then I would just handle this in JS, in the client, which is technically, the view. But MVC can be realised again in the "view" (model binding and events on view state for example), as well as between the client and server. So it really depends on the details of what you're dealing with.

  • I am using C# WinForms. So the View is a Form, and the Model and Controller are classes I created. – Sipo Feb 27 '17 at 11:38
  • Why are you using the MVC pattern in a C# WinForm application? – Martin Blore Feb 27 '17 at 11:40
  • 1
    Actually, after reading this: stackoverflow.com/questions/2056/…, my code seems to be more of MVP then MVC. – Sipo Feb 27 '17 at 11:52
  • 1
    It can be a good exercise to try and recreate MVP/MVC in WinForms, certainly not easier than doing it in a web environment, but sure you can do it. As you pointed out above in that link, it already is doing MVP for you without the need of seperate 'controller' classes, as also would a web SPA application based in HTML/JS would. It's good that you're exploring the patterns. Good luck. – Martin Blore Feb 27 '17 at 12:01
  • 2
    @MartinBlore I have to disagree on your statement regarding a Form being a "controller". A Form contains the widgets, fonts, colours, layout, etc; so it's very much a View (even if you split it across multiple files with partial it's still all the same class). The goal of the MVC pattern is clean separation of behaviour away from layout/presentation, which means putting behaviour in a separate class independent of the View. By putting behaviour inside the View/Form you effectively have no controller at all. – Ben Cottrell Feb 27 '17 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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