2

I have been using the solution below with beta 5, but this no longer works in RC1 : How to access RouteData from an ASP.Net 5 Tag Helper in MVC 6

ViewContext is null when it gets hit. Do I need to instantiate the ViewContext somewhere eg in Startup?

EDIT : Here is my ConfigureServices method :

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
        }
Community
  • 1
  • 1
user517406
  • 13,623
  • 29
  • 80
  • 120

1 Answers1

0

Did you use the correct ViewContext attribute? ViewContext attribute is in Microsoft.AspNet.Mvc.ViewFeatures, not in Microsoft.AspNet.Mvc.Rendering (where ViewContext class itself is).

Danny van der Kraan
  • 5,344
  • 6
  • 31
  • 41