3 回答

TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個(gè)贊
使用TempData
表示僅在一個(gè)請(qǐng)求到下一個(gè)請(qǐng)求之間存在的一組數(shù)據(jù)
[HttpPost]
public ActionResult FillStudent(Student student1)
{
TempData["student"]= new Student();
return RedirectToAction("GetStudent","Student");
}
[HttpGet]
public ActionResult GetStudent(Student passedStd)
{
Student std=(Student)TempData["student"];
return View();
}
另一種方法 使用查詢字符串傳遞數(shù)據(jù)
return RedirectToAction("GetStudent","Student", new {Name="John", Class="clsz"});
這將生成一個(gè)GET請(qǐng)求,例如 Student/GetStudent?Name=John & Class=clsz
確保您要重定向到的方法已裝飾,[HttpGet]因?yàn)樯厦娴腞edirectToAction將發(fā)出帶有HTTP狀態(tài)代碼302 Found的GET請(qǐng)求(執(zhí)行url重定向的常用方法)

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
只需調(diào)用不需要的動(dòng)作redirect to action或new模型的關(guān)鍵字即可。
[HttpPost]
public ActionResult FillStudent(Student student1)
{
return GetStudent(student1); //this will also work
}
public ActionResult GetStudent(Student student)
{
return View(student);
}
- 3 回答
- 0 關(guān)注
- 650 瀏覽
添加回答
舉報(bào)