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

Confused by Edit Not Accepting Some Numbers

$
0
0

I have the following in Edit on controller:

 // GET: WaterBodies/Edit/5
        public async Task<IActionResult> Edit(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            var waterBody = await _context.WaterBodys.SingleOrDefaultAsync(m => m.WaterBodyID == id);
            if (waterBody == null)
            {
                return NotFound();
            }
            ViewData["ConstructionID"] = new SelectList(_context.Constructions, "ConstructionID", "iConstruction", waterBody.ConstructionID);
            ViewData["LocationID"] = new SelectList(_context.Location, "LocationID", "iLocation", waterBody.LocationID);
            ViewData["PoolTypeID"] = new SelectList(_context.PoolTypes, "PoolTypeID", "iPoolType", waterBody.PoolTypeID);
            ViewData["SiteID"] = new SelectList(_context.Sites, "SiteID", "SiteName", waterBody.SiteID);
            return View(waterBody);
        }

        // POST: WaterBodies/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost, ActionName("Edit")]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> EditPost(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            var wbToUpdate = await _context.WaterBodys.SingleOrDefaultAsync(w => w.WaterBodyID == id);

            if (await TryUpdateModelAsync<WaterBody>(
                wbToUpdate,"",
                w => w.WBName, w => w.SiteID, w => w.ConstructionID, w => w.Depth,
                w => w.Length, w => w.LocationID, w => w.PoolTypeID))
            {
                try
                {
                    await _context.SaveChangesAsync();
                    return RedirectToAction("Index");
                }


                catch (DbUpdateException /*ex*/)
                {
                    //Log the error uncomment ex to write a log
                    ModelState.AddModelError("", "Changes not saved.  " +"Try again.  If error recurs see system administrator.");
                }

            }
            return View(wbToUpdate);
        }

The model is set up as:

 public class WaterBody
    {
        public int WaterBodyID { get; set; }

        [Display(Name = "Site")]
        public int SiteID { get; set; }

        [Required]
        [StringLength(500)]
        [Display(Name = "Water Body Name")]
        public string WBName { get; set; }


        [Display(Name = "Location")]
        public int LocationID { get; set; }

        [Display(Name = "Pool Type")]
        public int PoolTypeID { get; set; }


        [Display(Name = "Construction")]
        public int ConstructionID { get; set; }

        public decimal Length { get; set; }
        public decimal Width { get; set; }
        public decimal Depth { get; set; }



       // public ICollection<Site> Site { get; set; }

        public Site Sites { get; set; }

        public Construction Construction { get; set; }
        public Location Location { get; set; }

        public PoolType PoolType { get; set; }
        public ICollection<Equipment> Equipment { get; set; }

        public ICollection<Job> Job { get; set; }

        public ICollection<ChemicalOurTargets> ChemicalOurTargets { get; set; }

        public ICollection<WaterBodyLog> WaterBodyLog { get; set; }



        [Display(Name = "Volume")]
        public decimal PoolVolume
        {
            get
            {
                return Length * Width * Depth;
            }
        }

        [Display(Name = "Area")]

        public decimal PoolArea
        {
            get
            {
                return Length * Width;
            }
        }

    }

On setting some pools up I knew the volume so made up the length and width to get some sizing into the seed data.

Now we went through and edited the records to the real measurements.  On entering the real measurements we found in some cases the width was refused.

What I mean for example is for mathematical ease I used 10 m in the width in the seed data.  But on site the measurement is say 8.7.  We enter 8.7 and click save , without making any changes the width is saved as 10. 

Anyone seen this before?  I thought I may have an int in the code somewhere but cant see it.

Anyone got a suggestion on how I can fix this or find the cause? 


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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