在ASP.NET MVC中,RedirectToAction方法会将请求重定向到另一个操作方法,但不会刷新页面。如果需要刷新页面,可以使用以下解决方法之一:
public ActionResult MyAction()
{
// 执行某些操作
// 使用JavaScript刷新页面
return Content("");
}
public ActionResult MyAction()
{
// 执行某些操作
// 重定向到另一个操作方法,并传递refresh参数来指示页面刷新
return RedirectToAction("AnotherAction", new { refresh = true });
}
public ActionResult AnotherAction(bool refresh = false)
{
// 执行某些操作
if (refresh)
{
// 执行页面刷新的操作
// 可以使用JavaScript刷新页面,或者返回带有刷新标记的视图
}
return View();
}
这样,在重定向到AnotherAction方法时,可以通过传递refresh参数来指示页面刷新,并在AnotherAction方法中根据该参数执行相应的操作。
请注意,以上示例中的代码仅为演示目的,并可能需要根据实际需求进行调整。