I suggest you ...

Make the controller available to the views that it creates

I would like to be able to add specific methods to a view that is created, or at the very least have the public methods off of the controller itself available to the view.

13 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    anonymousanonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    11 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Jens HofmannJens Hofmann commented  ·   ·  Flag as inappropriate

        ViewContext.Controller is what you are searching for. But you should really think about carefully whether to use it or not.

      • MQMQ commented  ·   ·  Flag as inappropriate

        This certainly violates MVC pattern. If you have the urge to get to the controller from the view, you need to double check your design.

      • Jeffrey PalermoJeffrey Palermo commented  ·   ·  Flag as inappropriate

        If there is a property of the controller whose value you need in the view, consider sending that value/object to the view explicitly. Allowing the view to "poke around" back at the controller could add to unnecessary coupling. Sending another object to the view instead will preserve the one-way and explicit relationship between controller and view.

      • Stephen BurnsStephen Burns commented  ·   ·  Flag as inappropriate

        No thanks. Views should know nothing about controllers. Review the actual MVC pattern please.

      • James KovacsJames Kovacs commented  ·   ·  Flag as inappropriate

        -1! I cannot express how bad an idea this is. One of the main points of MVC is decoupling the view from the controller/model. If you need methods in your view, use HTML helpers.

      • vinbrown2vinbrown2 commented  ·   ·  Flag as inappropriate

        Hmm, I wouldn't do it. What methods would you like to call from the view? Every example I can think of sends up flags saying 'please don't do this'.

      • Koen WillemseKoen Willemse commented  ·   ·  Flag as inappropriate

        Not a good idea.The only code the view should incorperate is some basic looping to generate the correct html, not much more.

      • Brendan EnrickBrendan Enrick commented  ·   ·  Flag as inappropriate

        One of the reasons for MVC's existence is to prevent this type of logic from being in the view.

      Feedback and Knowledge Base