Thursday, November 9, 2017

checkbox issue

CheckedStatus = entity.tbl_educcation.any(m=>EDUids.Contains(m.EDUid)

 @Html.CheckBox("cmngoals_chek[" + i + "].Selected", Model.PatientID != 0 ? Model.cmngoals.Split(',').Any(j => Convert.ToInt32(j) == i) : false, new { @name = "cmngolas" })









using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace MyProject.Models.EmpModels
{
 
    public class EmployeeModel1
    {
        public EmployeeModel1()
        {
         
        }
        public int Empno { get; set; }

        //[Required(ErrorMessage ="please enter Name")]
        [Display(Name ="Employee Name")]
        public string Ename { get; set; }

         [Required]
        [Display(Name = "Employee Job")]
        public string Job { get; set; }


        //[Required(ErrorMessage = "please enter Manager")]
        [Display(Name = "Manager Name")]
        public Nullable Mgr { get; set; }

        //[Required(ErrorMessage = "please enter HireDate")]
        [Display(Name = "Joining Date")]
        public Nullable HireDate { get; set; }
        [Display(Name = "Employee Salary")]
        public Nullable Sal { get; set; }

        [Display(Name = "Commission")]
        public Nullable Comm { get; set; }

        //[Required(ErrorMessage = "please Select Department")]
        public int? Deptno { get; set; }
        public bool IsActive { get; set; }

        public string EDU_IDs { get; set; }
    }

    [Table("Dept")]
    public class DepartmentModel1
    {
        [Key]
        public int Deptno { get; set; }
        public string DName { get; set; }
        public string Loc { get; set; }
           
    }


    [Table("tbl_Education")]
    public class EducationModel
    {
        [Key]
        public int EDU_ID { get; set; }
        public string EDU_Name { get; set; }
        public bool CheckedStatus { get; set; }
    }
    public class EmployeeViewModel
    {
        public List DepartmentList { get; set; }
        public EmployeeModel1 employees { get; set; }

        public List ManagerList { get; set; }

        public List Educations { get; set; }

    }
}

================================================

 public ActionResult Edit(int id)
        {
            var entity = new EmployeeDBContext();
            var e = entity.Emps.SingleOrDefault(m => m.Empno == id);
            if (e == null) return HttpNotFound();

            EmployeeViewModel employeeviewmodel = new EmployeeViewModel
            {
                employees = new EmployeeModel1
                {
                    Empno = e.Empno,
                    Ename = e.Ename,
                    Sal = e.Sal,
                    Comm = e.Comm ?? 0,
                    Deptno = e.Deptno,
                    HireDate = e.HireDate,
                    IsActive = e.IsActive,
                    Job = e.Job,
                    Mgr = e.Mgr,
                    EDU_IDs = e.EDU_ID
                },
                DepartmentList = entity.Depts.Select(D => new DepartmentModel1 { Deptno = D.Deptno, DName = D.DName }).ToList(),
                ManagerList = entity.Emps.Select(E => new EmployeeModel1 { Empno = E.Empno, Ename = E.Ename }).ToList(),
                Educations = entity.tbl_Education.Select(ED => new EducationModel {
                    EDU_ID = ED.EDU_ID,
                    EDU_Name = ED.EDU_Name,
                    CheckedStatus = false
        }).ToList()
            };
            return View("Index", employeeviewmodel);
        }
===================================================



            @Html.Label("Education:", new { @class = "form-check-label" })
           
           
                    @for (int i = 0; i < Model.Educations.Count; i++)
                    {
                       
  •          
  •                         @Html.CheckBoxFor(m => m.Educations[i].CheckedStatus, new { @id = "chkEdu" + Model.Educations[i].EDU_ID, @class = "form-check-input" })
                            @Html.DisplayFor(m => m.Educations[i].EDU_Name)
                            @Html.HiddenFor(m => m.Educations[i].EDU_ID)
                            @Html.HiddenFor(m => m.Educations[i].EDU_Name)
                       
                    }
               
           

    No comments:

    Post a Comment

    javascript Filter/index off

     var family = [{"name":"Jack",  "age": 26},               {"name":"Jill",  "age"...