Accessing Route Data from Tag Helper in ASP.NET 5 RC1

324 Views Asked by At

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
        }
1

There are 1 best solutions below

0
Danny van der Kraan On

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).