Asp.net core TempData give 500 error when adding list and redirect to another view

后端 未结 3 1025
清歌不尽
清歌不尽 2020-12-31 08:40

I am try to build alerts list and added them to TempData. But it work if I did not do redirect. When I do redirect it give me 500 error. I set break point in vi

3条回答
  •  失恋的感觉
    2020-12-31 09:06

    Did you configure Session? TempData is using session behind the scenes.

    Project.json

    "Microsoft.AspNetCore.Session": "1.1.0"
    

    Here is the Startup.cs file. - ConfigureServices method

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSession();
        services.AddMvc();
    }
    

    And Configure method.

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseSession();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
    

    Now try with TempData, it will work.

    And you can set the environment with set ASPNETCORE_ENVIRONMENT=Development environment variable.

提交回复
热议问题