首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.NET MVC如何将数据从GET ActionResult传递到同一视图的POST ActionResult

问ASP.NET MVC如何将数据从GET ActionResult传递到同一视图的POST ActionResult
EN

Stack Overflow用户
提问于 2021-06-23 23:05:22
回答 1查看 29关注 0票数 0

我让这些创建ActionResults:

代码语言:javascript
复制
   // GET: WC_Inbox/Create
        public ActionResult Create(int? id)
        {
            System.Diagnostics.Debug.WriteLine("Employee ID was: " + id);
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Employee employee = db.Employees.Find(id);
            if (employee == null)
            {
                return HttpNotFound();
            }
            string fullName = employee.First_Name + " " + employee.Last_Name;
            System.Diagnostics.Debug.WriteLine("Employee full name: " + fullName);
            ViewBag.EmployeeID = id;
            ViewBag.Name = fullName;
            ViewBag.Status = "Pending";
            return View();
        }

        // POST: WC_Inbox/Create
        // To protect from overposting attacks, enable the specific properties you want to bind to, for 
        // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "ID,InboxID,EmployeeID,Org_Number,Hire_Date,Job_Title,Work_Schedule,Injury_Date,Injury_Time,DOT_12,Start_Time,Injured_Body_Part,Side,Missing_Work,Return_to_Work_Date,Doctors_Release,Treatment,Injury_Description,Equipment,Witness,Questioned,Medical_History,Inbox_Submitted,Comments,User_Email,Contact_Email,Specialist_Email,Optional_Email,Optional_Email2,Optional_Email3,Optional_Email4,Status,Add_User,Date_Added")] WC_Inbox wC_Inbox)
        {
            if (ModelState.IsValid)
            {
                //Get logged in windows user, get the date right now, and create the wcInbox unique ID
                var userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                wC_Inbox.Add_User = userName;
                wC_Inbox.Date_Added = DateTime.Today;
                db.WC_Inbox.Add(wC_Inbox);
                db.SaveChanges();
                SendEmailIQ();
                return RedirectToAction("Index");
            }

            ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "First_Name", wC_Inbox.EmployeeID);
            return View(wC_Inbox);
        }

我需要将值fullName从GET方法传递给POST方法。有几个帖子询问如何将数据从一个动作结果传递到另一个动作结果,但我还没有见过这样的帖子。我不知道如何将数据从GET Create传递到POST Create,或者在数据发送后如何检索数据。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-24 00:30:39

您不能在post方法中需要get方法时发送数据或从Get方法中检索数据,因为Get方法已经执行完毕并被清除。我建议您要么在发出post请求时在要发布的页面上添加一个隐藏字段,要么重新获取post请求中的数据。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68102424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档