Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Unable to Delete A Record

$
0
0

Hi,

The HttpPost seems to be in problem in an ASP Core CRUD.

SrcSys & CustId represent the elements of composite key:

        public async Task<IActionResult> Delete(string _SrcSys, string _CustId)
        {
            if (_SrcSys == null || _CustId == null)
            {
                return NotFound();
            }
            var customer = await _context.Customers
                .AsNoTracking()
                            .SingleOrDefaultAsync(Cust => Cust.SrcSys == _SrcSys && Cust.CustId == _CustId);
            if (customer == null)
            {
                return NotFound();
            }
            return View(customer);
        }

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> DeletePost([Bind("SrcSys,CustId,CustNm")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Remove(customer);
                await _context.SaveChangesAsync();
                ViewData["ErrorMessage"] = customer.CustId;
                return RedirectToAction("Index");
            }
            return View(customer);
        }

I am led to the Internal Server Error page declaring:

"Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions"

While it's the local PC there can't be a chance of concurrency I think.

Please see if you can help.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>