2

以下のソリューションをベータ 5 で使用していますが、これは RC1 では機能しなくなりました: How to access RouteData from an ASP.Net 5 Tag Helper in MVC 6

ヒットすると、ViewContext は null になります。スタートアップなどのどこかで 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
        }
4

1 に答える 1

0

正しい ViewContext 属性を使用しましたか? ViewContext 属性は、Microsoft.AspNet.Mvc.Rendering (ViewContext クラス自体がある場所) ではなく、Microsoft.AspNet.Mvc.ViewFeatures にあります。

于 2016-04-05T13:48:08.480 に答える