相关疑难解决方法(0)

将变量从[HttpPost]方法传递给[HttpGet]方法

我正在将视图从[HttpPost]方法重定向到[HttpGet]方法.我已经开始工作,但想知道这是否是最好的方法.

这是我的代码:

[HttpPost] 
public ActionResult SubmitStudent()
{ 
StudentViewModel model = TempData["model"] as StudentResponseViewModel; 

TempData["id"] = model.Id; 
TempData["name"] = model.Name; 

return RedirectToAction("DisplayStudent"); 
}

[HttpGet] 
public ActionResult DisplayStudent() 
{ 
ViewData["id"] = TempData["id"]; 
ViewData["name"] = TempData["name"]; 

return View(); 
}
Run Code Online (Sandbox Code Playgroud)

视图:

<%@ Page 
Language="C#"
Inherits="System.Web.Mvc.ViewPage"
 %> 
<html>
 <head runat="server"> 
<title>DisplayStudent</title> 
</head> 
<body> 
<div> 
<%= ViewData["id"]%> <br /> 
<%= ViewData["name"]%> 
</div> 
</body> 
</html>
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc http-get http-post http-redirect

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-mvc ×1

http-get ×1

http-post ×1

http-redirect ×1