2015-12-12 95 views
2

從標籤助手訪問路徑數據我一直在使用該解決方案具有以下5測試版,但不再RC1工作: How to access RouteData from an ASP.Net 5 Tag Helper in MVC 6在ASP.NET 5 RC1

ViewContext爲空時,它被擊中。我是否需要在啓動時實例化ViewContext?

編輯:這是我的ConfigureServices方法:

public void ConfigureServices(IServiceCollection services) 
     { 
      // Add framework services. 
      services.AddApplicationInsightsTelemetry(Configuration); 

      //EF 7 setup 
      services.AddEntityFramework() 
       .AddSqlServer() 
       .AddDbContext<ApplicationDbContext>(options => 
        options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); 

      services.AddIdentity<ApplicationUser, IdentityRole>() 
       .AddEntityFrameworkStores<ApplicationDbContext>() 
       .AddDefaultTokenProviders(); 

      // Add MVC services to the services container. 
      services.AddMvc(); 

      //Add Cors support to the service 
      services.AddCors(); 

      var policy = new Microsoft.AspNet.Cors.Infrastructure.CorsPolicy(); 

      policy.Headers.Add("*"); 
      policy.Methods.Add("*"); 
      policy.Origins.Add("*"); 
      policy.SupportsCredentials = true; 

      services.Configure<CorsOptions>(x => x.AddPolicy("mypolicy", policy)); 

      // Add application services. 
      services.AddTransient<IEmailSender, AuthMessageSender>(); 
      services.AddTransient<ISmsSender, AuthMessageSender>(); 
      services.AddScoped<IMainRepository, MainRepository>(); //dependency injection config 
     } 

回答

0

是否使用了正確的ViewContext屬性? ViewContext屬性在Microsoft.AspNet.Mvc.ViewFeatures中,而不在Microsoft.AspNet.Mvc.Rendering(其中ViewContext類本身是)。