public class HomeController : Controller
{
public ActionResult Index()
{
#region View()的三种写法
return View();//返回Index视图
return View("Create");//返回Create视图
return View("/User/Create");//不能返回User/Create视图,MVC只检查Score文件夹(action所在的控制器)及Share文件夹(模板页)
#endregion
}
}
public ActionResult RedirectJump(int age) { #region Redirect()的四种写法 return Redirect("Index");//进入无参或参数均为可空类型的Index()方法,并开始死循环 return Redirect("Index?age=16");//若Index()存在不可空类型的参数则必须传递参数值,后两项若存在不可空类型的参数可参照此解决方法 return Redirect("Create");//进入无参或参数均为可空类型的Create()方法 return Redirect("/User/Index");//进入无参或参数均为可空类型的User/Index()方法 #endregion }
public ActionResult RedirectToActionJump(string name, int age)
{
#region RedirectToAction()的四种写法
return RedirectToAction("Index", "Score");//进入无参或参数均为可空类型的Index()方法
return RedirectToAction("Index", "Score", new
{
name = "guo",
age = 16
});//若Index()存在不可空类型的参数则必须传递参数值,后两项若存在不可空类型的参数可参照此解决方法
return RedirectToAction("Create", "Score");//进入无参或参数均为可空类型的Create()方法
return RedirectToAction("Index", "User");//进入无参或参数均为可空类型的User/Index()方法
return RedirectToAction("Index", "User", new { name = "guoguo", age = "18" });//进入无参或参数均为可空类型的User/Index()方法时传递参数
#endregion
}
<a href="/Home/Logout" class="easyui-linkbutton" plain="true" iconCls="icon-power-blue">退出</a>
public ActionResult Logout()
{
Session.Abandon();
return Redirect("/Login/Index");
//return RedirectToAction("Index", "Login");
}
function logout() {
alert("logout()");
$.ajax({
type: "post",
url: "/Home/Logout",
success: function (data) {
//window.location.href = ‘/Login/Index‘;
window.location.href = ‘@Url.Action("Index", "Login")‘;
},
error: function (err) { }
});
}
更多了解:https://blog.csdn.net/xiaouncle/article/details/83020560
原文:https://www.cnblogs.com/mvpbest/p/13488998.html