コード例 #1
0
        public async Task <IActionResult> Create([Bind("ProductID,Name")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("OfferName")] Offer offer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(offer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(offer));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("OfferProductID,OfferName,ProductID")] OfferProduct offerProduct)
        {
            if (ModelState.IsValid)
            {
                _context.Add(offerProduct);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OfferName"] = new SelectList(_context.Offer, "OfferName", "OfferName", offerProduct.OfferName);
            ViewData["ProductID"] = new SelectList(_context.Product, "ProductID", "ProductID", offerProduct.ProductID);
            return(View(offerProduct));
        }