Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
in my mvc application i used "ul","li" for display menu in Layout.cshtml page.

i want to hide and show the values according to user login in home controller.

if account people login into this website, then only account details will be shown.

else if, other poeple login,then account menu will not to be shown to them,
instead other menu details will be shown.

attaching the code herewith:

HTML
<ul id="nav">   
            <li><a href="../Home/Create">Application Registration</a></li>
            <li><a href="../Home/IssuePaymentLetter">Payment Letter</a></li>
            <li><a href="../Home/IssueOfNoc">Issue Of NOC</a></li>

            <li id="li19"><a>Regretted Application</a>
                <ul>
                    <li id="liResubmit" class="Submenuheader"><a href="../Home/SaveWebgridCheckedValuesIntoDatabase">Re-submit Earlier Regretted Appl.</a></li>
                    <li id="liCFCHandoverRegrettedApplication" class="Submenuheader"><a href="../Home/Index11">CFC Handover Regretted Application</a></li>
                </ul>
            </li>

             <li id="li19"><a>Account</a>
                <ul>
                    <li id="li20" class="Submenuheader"><a href="../Home/ReceivePayment">Receive Payment</a></li>
                    <li id="li21" class="Submenuheader"><a href="../Home/Index11">CFC Handover Regretted Application</a></li>
                </ul>
            </li>

             <li id="li19"><a>Reports</a>
                <ul>
                    <li id="li20" class="Submenuheader"><a href="../Home/DailyReport">Daily Report</a></li>
                    <li id="li21" class="Submenuheader"><a href="../Home/Index11">CFC Handover Regretted Application</a></li>
                </ul>
            </li>
           
            <li>
                <a>
                    </a><a href="../Home/Index">Log Out</a>  
                
            </li>
        </ul>


What I have tried:

i had attached details in as.net mvc application
Posted
Updated 3-Feb-17 22:10pm
v3
Comments
Suvendu Shekhar Giri 31-Jan-17 2:25am    
What have you tried so far to show/hide?
What is the issue with tried code?
Kats2512 31-Jan-17 4:29am    
what you should do is check if the user is assigned to a role, depending on the role of the user display the menu items accordingly. if you do not have role based security in your project then I suggest that you read it up and implement. If you do have role based security then the below could assist you

for example once the user has been logged in do a check like:

@if (User.IsInRole("Admin"))
{
//your menu items here
}
Nathan Minier 1-Feb-17 7:47am    
That's a solid answer, the only notable addition I'd suggest is adding a link that gives some context for RBAC and post this as an answer.
Kats2512 1-Feb-17 8:20am    
I have placed a link in the answer that I have just posted, the link definitely contains the menu solution that this person has asked about

1 solution

you can generate dynamic navbar . this link may help you
Dynamic Navbar in MVC - asp.net tips and tricks[^]
 
Share this answer
 

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