我想知道,有什麼技術,所以我們可以在RedirectToAction
我們可以在RedirectToAction中將模型作爲參數傳遞嗎?
對於示例轉發Model
作爲參數:
public class Student{
public int Id{get;set;}
public string Name{get;set;}
}
控制器
public class StudentController : Controller
{
public ActionResult FillStudent()
{
return View();
}
[HttpPost]
public ActionResult FillStudent(Student student1)
{
return RedirectToAction("GetStudent","Student",new{student=student1});
}
public ActionResult GetStudent(Student student)
{
return View();
}
}
我的問題 - 我可以通過RedirectToAction中的學生模型?
當然,這是一個有效的通話。它不會被路由嗎? –
我試過了,但沒有找到模型值 – Amit
由於路徑字典處理對象,嘗試改變'GetStudent'動作來接受'對象'並將其轉換爲'Student'。另一個選擇是在從'FillStudent'傳遞它時使用JSON序列化它。 –