小编caz*_*ise的帖子

如何基于登录用户 Asp.net mvc 隐藏/显示菜单项

我正在开发一个 ASP.Net MVC 4 应用程序。_Layout 主视图包含一个菜单,我想根据您是否以用户身份登录来隐藏菜单中的某些项目,如果您以管理员身份登录,则显示。

我尝试过的方法确实在客户端的菜单中隐藏了链接选项卡,但是当我以管理员身份登录时,它也会在我希望管理员查看它时隐藏相同的链接选项卡。

只是提一下我没有任何角色或管理员控制器登录基于用户

将不胜感激提前感谢一些帮助。

<nav>
<ul id="menu">
    <li>@Html.ActionLink("Rep Home", "Index" , "Audit")</li>
    <li>@Html.ActionLink("Log Out", "Login" , "Home")</li>  
    @if (ViewContext.HttpContext.User.IsInRole("Admin"))
    {
        <li><a href="http://example/reports/?report=auditDetails" target="_blank">View  your report</a></li>
    }        
</ul>
Run Code Online (Sandbox Code Playgroud)

public class AccountController : Controller
{
    //
    // GET: /Account/Login

    [AllowAnonymous]
    public ActionResult Login(string returnUrl)
    {
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }

    //
    // POST: /Account/Login

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult Login(LoginModel model, string returnUrl)
    {

        if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
        {
            FormsAuthentication.SetAuthCookie(model.UserName, false);
            return RedirectToLocal(returnUrl); …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc asp.net-mvc-4

3
推荐指数
1
解决办法
1万
查看次数

如何在表格中添加垂直滚动条(剃刀视图)

我正在努力在我的视图(razor/html)中添加垂直滚动条。我想将它放在包装我的数据的数据中。我曾尝试过但没有成功。

如果可能的话,需要一些帮助。

<table id = "MenuItem"  class="promo full-width alternate-rows" style="text-align: center; ">  <!-- Cedric Kehi DEMO CHANGE -->



            <tr>
                <th>Product Code
                </th>

                <th>Description <!-- JACK EDIT -->
                </th>
                <th>Product Size
                </th>
                <th>Product Material
                </th>
                <th>Excluded?
                </th>
                <th>Order
                </th>
                <th>Actions</th>
            </tr>


        <tbody id ="scroll" style="overflow : scroll">


        @foreach (var item in Model.IndexList.OrderBy(x => x.ShuffleFunction))
        {




            <tr id ="trendingDisplay" data-model="model-1">



                    <td class="center-text">
                        @Html.DisplayFor(modelItem => item.ProductCode)
                    </td>
                   @* <td>
                        @Html.DisplayFor(modelItem => item.ProductTemplate.Description)
                    </td>*@
                    <td>
                        @Html.DisplayFor(modelItem => item.Description)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Size.SizeTitle)
                    </td> …
Run Code Online (Sandbox Code Playgroud)

html jquery-ui scrollbar

1
推荐指数
1
解决办法
9945
查看次数