Question

I am using the asp.net MVC Framework. IN my application a user has to log in. And when the combination of username and password is correct, the div (or panel?) with with the menu in it, must become visible. But how can I do this? When a name my panel pnlMenu, in my controller i cannot do something like:

pnlMenu.visible = true;

So, how do i have to do this?

Was it helpful?

Solution

What you should do is in your controller check to see if a user is logged in and set a value in the ViewData like this:

ViewData["IsLoggedIn"] = true;

Then in your view you can set the visibility of the method based on this value. This way if you change the view later, or decide to have multiple views, they can each use this value and there isn't any coupling between your view and your controller.

OTHER TIPS

Create a method or property on your View that enables you to hide or show the appropriate controls ?

Then, in your Controller you can access that property or method of your View, can't you ?

You do not want to reference specific 'controls' on your View in your controller, since, one of the ideas of MVC is that you can just replace the UI with another implementation (web / win / ...) and make use of the same controllers and application logic. Then, you just want to describe an operation that your View should support, so, in the interface that describes the 'contract' that your View must support, you should create a method which is called 'ChangeState( bool loggedIn )' for instance.

In the controller, you can call this method when the user has logged in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top