Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 517k

DataType Bit in Sql

Jun 7 2021 12:42 PM

Hi

  I have IsActive = Bit type in Sql . In input form i have below code

<div class="form-group row">
                            <label for="IsActive" class="col-sm-3 col-form-label">IsActive</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="txtIsActive" Name="IsActive" placeholder="Active">
                            </div>
                        </div>

On Controller it gives message - [0] = "The value 'Y' is not valid for IsActive."

        [HttpPost]
        public ActionResult CreateEdit(Product objProduct)
        {
            if (ModelState.IsValid)
            {
                dbProduct.Add(objProduct);
            }
            else
            {
                var query = from state in ModelState.Values
                            from error in state.Errors
                            select error.ErrorMessage;
                var errors = query.ToArray();
            }
            return RedirectToAction("Index");
        }

*********************************************************

[Required]
        [Range(minimum: 1, maximum: 1)]
        public bool IsActive { get; set; }

Thanks


Answers (3)