Click here to Skip to main content
15,843,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How do i change main layout content from controller in MVC c#?

I have one layout,home view and user view.
That layout contains one menu bar and footer.
Am using this layout for home view and User view. This layout contains menu bar with log in and sign up options.
When the user logged in i will show user page view (but with same layout). I need to hide log in and sign up options instead of that i want to show logged in user name.

Is it possible? If yes how?
Actually my main layout has 3 menu links on top bar.Next to that login and sign up are there. I want to hide this once user get logged in.
Do i need to create different layout for user view page?
Posted
Updated 3-Apr-15 2:02am
v2

1 solution

a. Declare section in layout as
@RenderSection("Account_Control", required: false)

b. Account_Control is partial view. which contain Login and SignUp UI elements.

c. Define Account_Control Section in View which is for Authenticated User.

d. Obviously we don't have to Define Account_Control Section for view , which is for Anonymous user.


this is one way, where you can achieve the same requirement as you needed.
 
Share this answer
 
Comments
Am Gayathri 7-Apr-15 5:41am    
I got it.. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900