-1

MVC 3 を使用して動的なメニュー オプションを備えた Web サイトを構築しているため、ユーザーは、グループおよび個々の権限に基づいて表示が許可されているメニュー オプション (アクション リンク) のみを表示できます。

実行時に動的メニュー オプション (部分ビューへのリンク) を追加するにはどうすればよいですか? 可視性オプションを使用して、すべての部分ビューのすべてのリンクと、不要なビューの順番をハード コードしますか? データベースからリンクを動的に追加できますか?

明確にさせてください。ユーザーの管理、グループの管理、サプライヤーの管理、製品の管理、注文の管理など、すべてのメニュー オプションにアクセスできる管理者がいます。サプライヤーの管理と注文の管理のみを必要とする通常の販売スタッフがいます。したがって、これに基づいて、Manage Orders と Manage Suppliers というリンクを表示するだけで済みます。したがって、私が設定しようとしているリンクの動的な性質です。DBに権限を設定しました。

ジャワハル

4

2 に答える 2

0

IPrincipal でメソッド拡張を使用してこれを行う方法を見つけました

public static bool IsAllowed(this IPrincipal p, string menuid) { 
if (p.Identity.IsAuthenticated) { 
         //Code here to verify privillegs against Database
     } 
     return false; 
} 

This would keep it fairly neat in you Layout.cshtml. 

@if (User.IsAllowed("menuchoice1")) { 
        <a href="@Url.Action(...)">...</a> 
} 
@if (User.IsAllowed("menuchoice2")) { 
      <a href="@Url.Action(...)>...</a> 
} 

これが、同様のオプションを探している他の人に役立つことを願っています

于 2012-10-01T20:21:58.423 に答える
0

I am not sure I entirely understand what you mean when you say "links to partial views". You never really have a hyperlink to a partial view. The two possibilities I can think of are either you want to know how to embed the partial view conditionally, or you want to have hyperlinks to a controller action which returns the partial views.

In the first case, you can just put the @Html.RenderPartial call inside of an @if (myCondition == true) block. With that, the partial view will only be displayed if the condition passes.

In the second case, you can just always call the controller action. In your controller, only return the PartialView if your condition matches. Otherwise, return null.

于 2012-09-25T12:50:15.367 に答える