Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 90431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:52:20+00:00 2026-05-10T22:52:20+00:00

The question, in brief: In MVC, how do you distinguish between a checkbox click

  • 0

The question, in brief:

In MVC, how do you distinguish between a checkbox click (or a selectbox or listbox change) from a human meaning ‘Controller, modify the model’, and a checkbox click (or a selectbox or listbox change) from the Controller meaning ‘I’m updating the view because the model has changed’?


The example:

I have a JS app (all one big HTML+JS page; there’s a server behind it, and AJAX going on, but it’s not important to the example) which has the notion of ‘Vertices’ connected by ‘Edges’. The UI lets you add and remove Vertices on a map, and enable or disable Edges between pairs of Vertices.

There are two ways to disable an Edge from Vertex A to Vertex B:

  1. click on the Edge to make the ‘Edge Details’ window provide you with a ‘Disable This Edge’ button; or
  2. click on Vertex A (or B) to make the ‘Vertex Details’ window provide you with a checklist of nearby Vertices, from which you can uncheck Vertex B (or A).

Here’s how this works under the hood in MVC (but see the end of this post for an update, where I correct problems in my understanding):

  • Model: a list of Vertex objects and a list of Edge objects.
  • View: a GMaps UI, with markers and polylines, plus checkboxes and buttons and ‘Vertex Details’ and ‘Edge Details’ DIVs.
  • Controller:
    • JS functions that update the model when events on the checkboxes and buttons fire; and
    • JS functions that update the view when events on the models fire.

Here’s the specific inelegance:

  1. The user has the Vertex Details Window focused on Vertex A, and the Edge Details Window focused on the Edge from Vertex A to Vertex B.
  2. The user clicks ‘Disable This Edge’ in the Edge Details window.
  3. Controller function 1 gets the click event, and calls disable() on the Edge model object.
  4. The Edge model object fires the ‘I just got disabled’ event.
  5. Controller function 2 receives the ‘I just got disabled’ event, and
    1. redraws the Edge Details Window to say ‘I’m disabled!’ and
    2. unchecks Vertex B in the Vertex Details Window.
      1. Crap! This fires Controller function 1 again, which was listening for UI events that mean an edge was disabled!

So there’s an unnecessary re-update of the Model, and re-update of the View. In a more complex view with events that fire events that fire events, this can make for dozens of extraneous updates!


Update: a great answer.

I misunderstood MVC a bit. I don’t have just one View, as I described above: I have several Views into several Models. In particular, I have a checkbox-list View of Edges to a particular Node, and a separate, ‘detailed window-style’ View of an Edge.

Furthermore, I shouldn’t have one controller function updating all views when the Model changes: each View should modify itself when the Model changes.

So if each View registers for ‘state updated’ events on the Model, and each View updates itself upon receipt of those events, then the answer to my circular events question is simply this:

The checkbox-list View will disable checkbox events for the moment that it is updating the checkboxes after a Model state change.

Now if a user disables an Edge via the Edge Detail window, the Controller updates the Edge Model, the checkbox-list View receives notification of the update, and the checkbox-list View is smart enough to silence checkbox events while changing the status of the appropriate checkbox.

This is much more palatable than my original solution, where one Controller updates ALL Views — and thus has to know which views need special care and feeding to avoid loops. Instead, only the single View with troublesome UI elements has to deal with the problem.

Thanks to those who answered my question!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:52:20+00:00Added an answer on May 10, 2026 at 10:52 pm

    Just to recap the MVC model. Views should generally update themselves. Here’s how it works: a controller changes the state of the model, the model sends updates to its views, the views pull in new state from the model and update themselves. While controllers and views are generally bundled (i.e. drilling down on data in a graphic representation) they should never interact directly, only through the model. This in general of course.

    So the JS functions that update your views are not actually controllers, which is an important distinction. They should be considered part of your view. This might not be helpful to the problem at hand but I thought it merited pointing out.

    You can also not delete your model, I assume you mean you’re deleting someting from your model, since no views or controllers can actually exist (or be in a functional state) if they’re not backed by a model.

    Not being a JS code jockey and not having used gmaps I don’t really see where the problem is. Does changing the state of a checkbox(checked property) fire the onClick() event? It really shouldn’t IMHO but perhaps they implemented it that way, otherwise you could just attach your controller to the onClick() and add some logic to the checkbox (or, this being JS, in a function somewhere) to change the checkbox state. If that’s not possible, option 1 and 2 are definitely your best bet.

    addition: user interacting with a view

    So what happens when a user wants to interact with a view? Frequently a widget will include both a view and the controller. A checkbox has a view (you can see if it’s checked or not) and also a controller (you can click it). When you click the checkbox, in principle the following should happen:

    • checkbox controller receives the event
    • checkbox controller changes the state for the value this checkbox represents in the model
    • model updates listeners (including the checkbox)
    • checkbox updates its look to reflect that that value has changed

    The first step, how the controller receives the event is somewhat language dependent, but in OOP languages it’s likely a listener object attached to user interface events on this particular widget which either is the controller or notifies the controller of the user interaction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ryeguy, they last for the length of the connection. Per… May 12, 2026 at 1:17 am
  • Editorial Team
    Editorial Team added an answer You should use something like this pb.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(… May 12, 2026 at 1:17 am
  • Editorial Team
    Editorial Team added an answer Currently, each SCM plugin provides workspace cleanup functionality. Soon, core… May 12, 2026 at 1:17 am

Related Questions

I want to use forms authentication in asp.net mvc applications. I have searched a
Hey all. Okay here is the situation. I would like to be able to
Imagine this case: A color has an id. Easy enough. The same color can,
I'm currently looking at disaster recovery plans and restoring backups of master/msdb/model. In theory

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.