asp.net-mvc – 我们可以传递模型作为参数在RedirectToAction吗?
发布时间:2020-05-23 11:01:28 所属栏目:asp.Net 来源:互联网
导读:我想知道,有任何技术,所以我们可以传递Model作为参数在RedirectToAction 例如: public class Student{ public int Id{get;set;} public string Name{get;set;}} 控制器 public class StudentController : Controller{ public Acti
|
我想知道,有任何技术,所以我们可以传递Model作为参数在RedirectToAction 例如: 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吗? 解决方法您可以使用TempData[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();
}
方法2:使用查询字符串数据传递 或者你可以用查询字符串的帮助框架它 return RedirectToAction("GetStudent",new {Name="John",Class="clsz"});
这将生成一个GET请求 Student/GetStudent?Name=John & Class=clsz 但确保你有[HttpGet],因为RedirectToAction将发出GET请求(302) (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- VS2005(c#)项目调试问题解决方案集锦 转
- asp.net c#membership:如何做一个GetUsersInRoles(多个角色
- 使用实体框架在ASP.Net中创建报表
- asp.net-mvc – 在MVC WebApi中的方法如何映射到http动词?
- asp.net – 如何在web.config中增加执行sql查询的时间
- 实体框架 – 在每个单元测试之前重新创建和重新设置LocalDb
- 分步ASP.NET自动构建/部署
- asp.net-mvc – ASP.NET MVC – 从单个控制器动作返回不同的
- asp.net-mvc – 如何将变量传递给ASP.NET MVC应用程序中的自
- asp.net – dbo.TempGetStateItemExclusive3重复调用
