0

I am using ASP.NET Entity Framework and I have this text field, which is disabled:

@Html.TextBoxFor(model => model.consultant, new { @class = "form-control", disabled = "disabled" })

I have this on the Edit page, but when I goto save it, it updates consultant column as an empty string.

Here is the method code:

[HttpPost]
        [ValidateAntiForgeryToken]
        [Authorize]
        public ActionResult Edit([Bind(Include = "id,consultant,image,message,startStop")] SetupClass setupClass)
        {
            string[] username = User.Identity.Name.Split('\\');

            ViewBag.User = username[0];

            ViewBag.Renderings = dbRendering.Data.OrderBy(m => m.order).ToList();

            if (ModelState.IsValid)
            {
                db.Entry(setupClass).State = EntityState.Modified;
                db.SaveChanges();
                ViewBag.Message = "Updated";
                return View(setupClass);
            }
            return View(setupClass);
        }

I guess I could exclude the consultant column from the method as I don't need to update it at all.

user979331
  • 11,039
  • 73
  • 223
  • 418
  • 1
    Well, if it's disabled then it probably isn't sending a value to the server. Check the runtime values on `setupClass`. If it's empty, then that would be why it's saving as empty. Perhaps you instead want to include the field? Why is it disabled in the first place? – David Jul 26 '17 at 15:36
  • Possible duplicate of [Submitting the value of a disabled input field](https://stackoverflow.com/questions/4045648/submitting-the-value-of-a-disabled-input-field) – krillgar Jul 26 '17 at 15:38

0 Answers0