mercredi 26 juin 2019

I am new to mvc and want to save the checkbox data in the sql server using mvc I am new To MVC and want to save the checkbox

Controller Code: public ActionResult SaveRecord(CustomerCount cc) { try { CustomerCounterDBEntities1 dbs = new CustomerCounterDBEntities1(); List infos = dbs.CustomerInfoes.ToList(); ViewBag.CustomerInfoList = new SelectList(infos, "Name", "Mobile"); CustomerInfo ct = new CustomerInfo(); ct.CustomerID = cc.CustomerID; ct.Name = cc.Name; ct.Mobile = cc.Mobile; ct.Email = cc.Email; ct.Comments = cc.Comments; ct.Western_Union = cc.Western_Union; ct.Ria = cc.Ria; ct.Money_Gram = cc.Money_Gram; ct.Intel = cc.Intel; ct.JazzCash = cc.JazzCash; ct.Contact = cc.Contact; ct.No_Business = cc.No_Business; dbs.CustomerInfoes.Add(ct); dbs.SaveChanges(); int CustomerID = ct.CustomerID; return RedirectToAction("Index");

            }
       Model Code:
namespace Customer_Counter.Models
{
    public class CustomerCount
    {
       [Key]
        public int CustomerID { get; set; }

        public string Name { get; set; }
        public string Mobile { get; set; }
        public string Email { get; set; }
        public string Comments { get; set; }
        public Boolean Western_Union { get; set; }
        public Boolean Ria { get; set; }
        public Boolean Money_Gram { get; set; }
        public Boolean Intel { get; set; }
        public Boolean JazzCash { get; set; }
        public Boolean Contact { get; set; }
        public Boolean No_Business { get; set; }
    }
}
CustomerInfo:
namespace Customer_Counter.Models
{
    using System;
    using System.Collections.Generic;

    public partial class CustomerInfo
    {
        public int CustomerID { get; set; }
        public string Name { get; set; }
        public string Mobile { get; set; }
        public string Email { get; set; }
        public string Comments { get; set; }
        public Nullable<bool> Western_Union { get; set; }
        public Nullable<bool> Ria { get; set; }
        public Nullable<bool> Money_Gram { get; set; }
        public Nullable<bool> Intel { get; set; }
        public Nullable<bool> JazzCash { get; set; }
        public Nullable<bool> Contact { get; set; }
        public Nullable<bool> No_Business { get; set; }
    }
}
CustomerForm View: //Only the error part
  @Html.CheckBoxFor(Model => Model.Western_Union)
                    @Html.CheckBoxFor(Model => Model.Ria)
                    @Html.CheckBoxFor(Model => Model.Money_Gram)
                    @Html.CheckBoxFor(Model => Model.Intel)
                    @Html.CheckBoxFor(Model => Model.JazzCash)
                    @Html.CheckBoxFor(Model => Model.Contact)
                    @Html.CheckBoxFor(Model => Model.No_Business)

I am new To MVC and want to save the checkbox data in boolean form in sql server. The error is CS0266: Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)




Aucun commentaire:

Enregistrer un commentaire