C# MVC跳转

时间:2023-03-09 06:47:55
C# MVC跳转

MVC方式:

显示提示框,并返回上一页

return Content("<script>alert('暂时没有实践作业!');history.go(-1);</script>");

Redirect("/控制器/视图?参数");

return Redirect("/Home/Index?id=" + id + "&T=" + T + "");

RedirectToAction("视图",new { 参数 });

return RedirectToAction("Index", new { type =  });

RedirectToAction(view?参数,控制器);

return RedirectToAction("Index?id=" + id + "&type=1", "Home");

当用Redirect或者RedirectToAction的时候,尽量使用false参数。在网页浏览的时候,有可能因为没有false导致网页线程中断。(猜测,没证据)

return Response.Redirect(url1, false);
return RedirectToAction("Index", "Home", false);
return Redirect("/Index/Home");

return View()

//返回的是view页面,不会再走Controller
return View("Index");

其他方式:

void情况的跳转,可以在script里写js跳转

Response.Write("<script>alert('文件未占用或文件未生成,请稍后重试!');window.close(); </script>");