asp.net-mvc – 我们可以传递模型作为参数在RedirectToAction吗
发布时间:2020-12-15 18:51:23 所属栏目:asp.Net 来源:网络整理
导读:我想知道,有任何技术,所以我们可以传递Model作为参数在RedirectToAction 例如: public class Student{ public int Id{get;set;} public string Name{get;set;}} 控制器 public class StudentController : Controller{ public ActionResult FillStudent()
我想知道,有任何技术,所以我们可以传递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) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 将ASP.NET成员资格表添加到我自己的现有数据库中
- asp.net-mvc – ELMAH和SQL Server 2008 R2?
- asp.net-mvc-3 – Razor webgrid ajax分页和排序
- asp.net – 日期格式和区域设置
- asp.net – 我可以同时拥有Controller和ApiContr
- asp.net-mvc – ASP.NET MVC 4 – 301重定向Rout
- 模拟ASP.NET声明身份到Windows身份
- asp.net – HttpMessageHandler与DelegatingHand
- asp.net-mvc – 在IE中清除cookie后,保持用户登录
- asp.net – 谁能告诉我在Mvc视图中@using和@Mode
热点阅读