[英]How to get model data from a ViewResult in ASP.NET MVC RC1?
[英]Accessing Route Data from Tag Helper in ASP.NET 5 RC1
我一直在使用下面的Beta 5解决方案,但是它在RC1中不再起作用: 如何从MVC 6中的ASP.Net 5 Tag Helper访问RouteData
被击中时ViewContext为null。 我是否需要在某个地方(例如在Startup中)实例化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
}
您是否使用了正确的ViewContext属性? ViewContext属性位于Microsoft.AspNet.Mvc.ViewFeatures中,而不位于Microsoft.AspNet.Mvc.Rendering中(ViewContext类本身在其中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.