相关疑难解决方法(0)

在.NET Core MVC应用程序中使用TempData时出现错误500

您好,我正在尝试向其添加对象TempData并重定向到另一个控制器操作。使用时出现错误消息500 TempData

public IActionResult Attach(long Id)
{
    Story searchedStory=this.context.Stories.Find(Id);
    if(searchedStory!=null)
    {
        TempData["tStory"]=searchedStory;  //JsonConvert.SerializeObject(searchedStory) gets no error and passes 

        return RedirectToAction("Index","Location");
    }
    return View("Index");
}


public IActionResult Index(object _story) 
{             
    Story story=TempData["tStory"] as Story;
    if(story !=null)
    {
    List<Location> Locations = this.context.Locations.ToList();
    ViewBag._story =JsonConvert.SerializeObject(story);
    ViewBag.rstory=story;
    return View(context.Locations);
    }
    return RedirectToAction("Index","Story");
}
Run Code Online (Sandbox Code Playgroud)

PS阅读可能的解决方案我已添加 app.UseSession()Configure方法services.AddServices()中,ConfigureServices但方法无济于事。是否有任何我必须注意的模糊设置?

PS添加ConfigureServicesUseSession

配置服务

 public void ConfigureServices(IServiceCollection services)
            {
                services.AddOptions();
                services.AddDbContext<TreasureContext>(x=>x.UseMySql(connectionString:Constrings[3]));
                services.AddMvc();
                services.AddSession();
            }
Run Code Online (Sandbox Code Playgroud)

配置

public void Configure(IApplicationBuilder …
Run Code Online (Sandbox Code Playgroud)

c# tempdata asp.net-core

1
推荐指数
2
解决办法
2445
查看次数

标签 统计

asp.net-core ×1

c# ×1

tempdata ×1