2013-07-30 2 views
-5

ControllerContext 클래스에서 viewmodel을 가져와야합니다. viewmodel ControllerContext의 일부 속성을 읽어야합니다. 내가 어떻게 할 수 있을까 ??controllerContext에서 viewModel 가져 오기 MVC

using System; 
using System.Web; 
using System.Web.Routing; 
using System.Web.WebPages; 

namespace System.Web.Mvc 
{ 
    // Summary: 
    //  Encapsulates information about an HTTP request that matches specified System.Web.Routing.RouteBase 
    //  and System.Web.Mvc.ControllerBase instances. 
    public class ControllerContext 
    { 
     // Summary: 
     //  Initializes a new instance of the System.Web.Mvc.ControllerContext class. 
     public ControllerContext(); 
     // 
     // Summary: 
     //  Initializes a new instance of the System.Web.Mvc.ControllerContext class 
     //  by using the specified controller context. 
     // 
     // Parameters: 
     // controllerContext: 
     //  The controller context. 
     // 
     // Exceptions: 
     // System.ArgumentNullException: 
     //  The controllerContext parameter is null. 
     protected ControllerContext(ControllerContext controllerContext); 
     // 
     // Summary: 
     //  Initializes a new instance of the System.Web.Mvc.ControllerContext class 
     //  by using the specified request context and controller. 
     // 
     // Parameters: 
     // requestContext: 
     //  The request context. 
     // 
     // controller: 
     //  The controller. 
     // 
     // Exceptions: 
     // System.ArgumentNullException: 
     //  One or both parameters are null. 
     public ControllerContext(RequestContext requestContext, ControllerBase controller); 
     // 
     // Summary: 
     //  Initializes a new instance of the System.Web.Mvc.ControllerContext class 
     //  by using the specified HTTP context, URL route data, and controller. 
     // 
     // Parameters: 
     // httpContext: 
     //  The HTTP context. 
     // 
     // routeData: 
     //  The route data. 
     // 
     // controller: 
     //  The controller. 
     public ControllerContext(HttpContextBase httpContext, RouteData routeData, ControllerBase controller); 

     // Summary: 
     //  Gets or sets the controller. 
     // 
     // Returns: 
     //  The controller. 
     public virtual ControllerBase Controller { get; set; } 
     // 
     // Summary: 
     //  Gets the display mode. 
     // 
     // Returns: 
     //  The display mode. 
     public IDisplayMode DisplayMode { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the HTTP context. 
     // 
     // Returns: 
     //  The HTTP context. 
     public virtual HttpContextBase HttpContext { get; set; } 
     // 
     // Summary: 
     //  Gets a value that indicates whether the associated action method is a child 
     //  action. 
     // 
     // Returns: 
     //  true if the associated action method is a child action; otherwise, false. 
     public virtual bool IsChildAction { get; } 
     // 
     // Summary: 
     //  Gets an object that contains the view context information for the parent 
     //  action method. 
     // 
     // Returns: 
     //  An object that contains the view context information for the parent action 
     //  method. 
     public ViewContext ParentActionViewContext { get; } 
     // 
     // Summary: 
     //  Gets or sets the request context. 
     // 
     // Returns: 
     //  The request context. 
     public RequestContext RequestContext { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the URL route data. 
     // 
     // Returns: 
     //  The URL route data. 
     public virtual RouteData RouteData { get; set; } 
    } 
} 
+0

여기에 묻는 내용이 확실하지 않습니다. ControllerContext 내에서 다른 클래스에 액세스하려고합니까? 또는 ControllerContext의 속성에 액세스하려고합니까? –

+0

ViewData 또는 ViewModel에 대해 이야기하고 있습니까? – ataravati

+0

임의로 : /// 및 사용자 의견에 적합한 태그를 사용하지 않는 이유는 무엇입니까? – Stu

답변

2

시도 : 정확하게 가져올 필요가있을 때 그것은 분명하지 않다

ControllerContext.Controller.ViewData.Model 

이 데이터를 컨텍스트에서 가져 오지 만 이이후에만 사용 가능하다는 것을 알아야합니다. 0 이벤트 (ActionFilter과 동일한 메소드).

0

내가 질문을 이해 가정하면, 당신은 점 표기법으로 ControllerContext의 속성에 액세스 할 수 있습니다 :

ControllerContext.<PropertyName>