weixin_39017744
weixin_39017744
采纳率71.1%
2019-04-19 16:15

ASP.NET MVC5项目中如何从根据EF生成的Controller中Create抓取数据并跳转?

5

想在插入数据后跳转到MEdit的页面,必须要抓取这个BidId.现在的问题应该是不会抓取当前的BidId。

public ActionResult Create(int bid, int sid, string sname, string btype, string btitle, string detail, int budget, DateTime bend)
        {
            var model = new BidF();
            model.BidId = bid;
            model.UserId = User.Identity.GetUserId();
            model.UserName = User.Identity.GetUserName();
            model.StoreId = sid;
            model.StoreName = sname;
            model.Title = btitle;
            model.BidType = btype;
            model.FBudget = budget;
            model.FDetail = detail;
            model.BidEnd = bend;
            return View(model);
        }

        // POST: BidFs/Create
        // To protect from overposting attacks, please 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,BidId,UserId,UserName,Title,BidType,BidEnd,Paid,StoreId,StoreName,FBudget,FDetail,DeliveryStart,DeliveryFinish")] BidF bidF)
        {
            if (ModelState.IsValid)
            {
                db.BidFs.Add(bidF);
                db.SaveChanges();
                return RedirectToAction("MEdit","Bids");
            }

            return View(bidF);
        }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • caozhy 回答这么多问题就耍赖把我的积分一笔勾销了 2年前

    可以放在 ViewBag 或者 TempData 集合,在页面里取出来用 ViewBag,在下一个跳转里面取出来,用 TempData

    点赞 评论 复制链接分享

为你推荐