2013-04-05 2 views
1

사이트의 모든 작업에 대한 작업 링크를 만들려면 어떻게해야합니까?
액션 링크를 메뉴 시스템에 넣고 싶습니다.사이트의 모든 작업 검색

내가 여기

foreach controller in controllers { 
    foreach action in controller{ 
     stringbuilder.writeline(
      "<li>"+actionlink(menu, action, controller)+"<li>" 
     ); 
    } 
} 

답변

2

는 여기에 내 걸릴입니다 멤버십 구현에서 정의한 역할에 따라 다릅니다.

+0

공급자를 살펴 봤는데 좀 더 살펴볼 필요가 있지만 xml을 통해 메뉴를 정의해야하는 것처럼 보입니까? –

+0

예, XML을 사용하여 메뉴를 정의해야합니다. 그러나 내가 제공 한 코드를 사용하여 초기 목록을 얻을 수 있습니다. 그래도 어떤 작업이 어떤 작업에 액세스 할 수 있는지 정의해야합니다. – amhed

+0

사용자가 정의 할 수있는 권한 기반 사용자 권한이 있습니다. 멀티 테넌트 시스템이므로 테이블 기반 또는 협약 기반이어야합니다. 우리는 후자가 작동하도록 노력하고 있습니다. –

0

과 같은 작업을 수행 할 수 있습니다 기대했다입니다 방법 당신이 Assembly.GetExportedTypes()하여 프로젝트의 모든 컨트롤러를 찾을 만 하위를 필터링해야 목표를 달성하기위한 컨트롤러 Asp.net Mvc: List all the actions on a controller with specific attribute 또는 Accessing the list of Controllers/Actions in an ASP.NET MVC application 에서 모든 작업을 얼마나 ControllerBase의 클래스와 각 컨트롤러에 대해 두 번째 링크의 new ReflectedControllerDescriptor(typeof(TController)).GetCanonicalActions()을 호출하십시오. 당신은 메뉴 시스템를 체크 아웃 MVC Sitemap Provider 필요한 경우

public static List<String> GetActions(Type controller) 
{ 
    // List of links 
    var items = new List<String>(); 

    // Get a descriptor of this controller 
    var controllerDesc = new ReflectedControllerDescriptor(controller); 

    // Look at each action in the controller 
    foreach (var action in controllerDesc.GetCanonicalActions()) 
    { 
     // Get any attributes (filters) on the action 
     var attributes = action.GetCustomAttributes(false); 

     // Look at each attribute 
     var validAction = 
      attributes.All(filter => !(filter is HttpPostAttribute) && !(filter is ChildActionOnlyAttribute)); 

     // Add the action to the list if it's "valid" 
     if (validAction) 
      items.Add(action.ActionName); 
    } 
    return items; 
} 

, 그것은 렌더링하는 무엇을 당신에게 절대 제어를 제공합니다 :

var controllers = Assembly.GetCallingAssembly().GetTypes().Where(type => type.IsSubclassOf(typeof(Controller))).ToList(); 
var controlList = controllers.Select(controller => 
            new 
            { 
             Actions = GetActions(controller), 
             Name = controller.Name, 
            }).ToList(); 

방법 GetActions 다음과 같이

+0

감사합니다. 월요일에 체크 아웃하겠습니다. –

+0

해당 게시물은 현재 컨트롤러에서만 작동합니다. 아흐메드의 게시물은보다 포괄적 인 내용이므로 답변으로 표시하겠습니다. –

관련 문제