0
我使用asp.net核心剃须刀引擎。我正在重定向到另一个函数,并且当我发送给它的函数是HttpPost时它不工作。当我将它改为HttpGet时,一切正常。为什么是这样?RedirectToAction是否仅适用于HttpGet?
这里是我的代码
static bool init = false;
// GET: /Home/
[HttpGet]
[Route("")]
public IActionResult Index()
{
if(init == false){
HttpContext.Session.SetString("Happiness", "190");
HttpContext.Session.SetString("Fullness", "190");
HttpContext.Session.SetString("Energy", "190");
HttpContext.Session.SetString("Meal", "3");
HttpContext.Session.SetString("Message", "");
HttpContext.Session.SetString("Tree", "/images/regular_tree.jpeg");
init = true;
}
ViewData["Tree"] = HttpContext.Session.GetString("Tree");
ViewData["Happiness"] = HttpContext.Session.GetString("Happiness");
ViewData["Fullness"] = HttpContext.Session.GetString("Fullness");
ViewData["Energy"] = HttpContext.Session.GetString("Energy");
ViewData["Meal"] = HttpContext.Session.GetString("Meal");
ViewData["Message"] = HttpContext.Session.GetString("Message");
if(Int32.Parse(HttpContext.Session.GetString("Happiness")) >= 100 &&
Int32.Parse(HttpContext.Session.GetString("Fullness")) >= 100 &&
Int32.Parse(HttpContext.Session.GetString("Energy")) >= 100){
System.Console.WriteLine("WinFunction");
System.Console.WriteLine("WinTwice");
return RedirectToAction("Win");
}
return View();
}
[HttpGet]
[Route("win")]
public IActionResult Win()
{
System.Console.WriteLine("Win");
return View();
}
[This page](http://stackoverflow.com/questions/129335/how-do-you-redirect-to-a-page-using-the-post-verb#answer-1343182)包含一个有趣的解决方法你可能可以使用。 –